docker / docker/docker-py

Closing stdin on a Running Container

Open
#1,507 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I am using docker version 2.1.0.

When starting a container the parameter stdin_open can be used to prepare the stdin socket for writing. I have had success doing this with code along these lines,

stdin_data = 'some data to send to stdin'

container = client.containers.run(image, detach=True, stdin_open=True)

socket = container.attach_socket(params={'stdin': 1, 'stream': 1})
os.write(socket.fileno(), stdin_data.encode())
socket.close()

exit_code = container.wait()

I have also found that this approach can easily hang indefinitely, if the underlying container is waiting for input. The reason seems to be be that the socket status is independent of the stdin_open parameter, so the code running in the container never receives an EOF-like sentinel on stdin.

Any suggestions on how to address this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the client.containers.run, container.attach_socket, and container.wait calls shown in the report, then reproduce the hang with a container waiting for input. Determine how the Docker Engine API and this library represent closing stdin; done means a documented, tested way to signal EOF and allow wait() to return.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.