2

The doc says

docker attach: Attach local standard input, output, and error streams to a running container

From my understanding, a running container can have many running processes, including those started using docker exec. So When using docker attach, which process am I attaching to exactly?

Marvis Lu
  • 441
  • 3
  • 10

2 Answers2

2

It should attach rather to the attach terminal’s standard input, output, and error, displaying the ongoing output or to control it interactively of the ENTRYPOINT/CMD process.

So it does not seem to be related to a specific process.

docker attach adds:

You can attach to the same contained process multiple times simultaneously, from different sessions on the Docker host.

Still the same process though.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Doesn’t stdin/stdout is related to a specific process? Let’s say I have two programs running in a container, both of which can handle user input and they are writing something to stdout at the same time. When I docker attach to that container, which process my stdin/stdout relate to? i.e., which process’s output can I see and which process my input sends to? – Marvis Lu Aug 11 '18 at 14:24
  • @MarvisLu 2 programs are always by one main process associated with the container (that is why you have docker run --init) See https://stackoverflow.com/a/33119321/6309. Honestly, I often start with the logs: docker logs aContainer. If those logs are done on stdout, you will see them there. No matter how many programs are running. – VonC Aug 11 '18 at 14:27
1

Whatever process has pid 1 in the container. If the image declared an ENTRYPOINT in the Dockerfile (or if you docker run --entrypoint ...), it's that program; if not, it's the command passed on the docker run command line or the Dockerfile's CMD.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Is there any way to attach to a specific process in the container? For example, if I docker exec a bash process but forget to add the -it flag, can I attach to the bash later? If not, the bash process would still running in the container until I manually kill it right? – Marvis Lu Aug 12 '18 at 01:56