Skip to content

Stdin remains open in Docker container after closing it on docker-java side via OkHttp #1448

@tejksat

Description

@tejksat

Steps to reproduce

  1. Use OkDockerHttpClient.
  2. 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
    
  3. Create a Docker container with the corresponding flags (StdInOnce flag is essential here):
    CreateContainerResponse container = dockerClient.createContainerCmd(imageId)
        .withStdinOpen(true)
        .withStdInOnce(true)
        .exec();
    
  4. Start the container.
  5. 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<>())
    
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions