Steps to reproduce
- Use
OkDockerHttpClient.
- Create Docker image based on
busybox and use the following sample script as its CMD:
#!/bin/sh
while read -r line; do echo "$line"; done
- Create a Docker container with the corresponding flags (
StdInOnce flag is essential here):
CreateContainerResponse container = dockerClient.createContainerCmd(imageId)
.withStdinOpen(true)
.withStdInOnce(true)
.exec();
- Start the container.
- Attach to the container:
PipedOutputStream stdinSource = new PipedOutputStream();
PipedInputStream stdin = new PipedInputStream(stdinSource);
ResultCallback.Adapter<Frame> resultCallback = dockerClient.attachContainerCmd(container.getId())
.withStdOut(true)
.withStdErr(true)
.withStdIn(stdin)
.withFollowStream(true)
.exec(new ResultCallback.Adapter<>())
- Close stdin:
stdinSource.close()
Expected result
The script receives EOF from stdin and the script finishes. The container is stopped.
Actual result
The script keeps waiting for stdin. The container keeps running.