LOGBOOK

HELP

Quiz Entry - updated: 2026.11.10

A container was started with docker run -itd … bash. You open a shell in it with docker exec -it <name> bash and type tty. Why does it print /dev/pts/1 and not /dev/pts/0?

/dev/pts/0 is already taken by the container's main process, the bash started with -it; exec -it starts a second process with its own new pseudo-terminal, numbered 1.

-t allocates a pseudo-terminal (pts), and the container numbers them from 0, just as every new terminal tab on a Linux desktop gets the next number. In this case:

  1. docker container run -itd … starts the container's main process (bash, PID 1) attached to the first pseudo-terminal, /dev/pts/0. With -d nobody is looking at it, but it exists and stays open.
  2. docker container exec -it … bash does not join that process. It starts an additional bash inside the same container and allocates a fresh terminal for it, /dev/pts/1.

That is also the practical difference between exec and attach: docker attach connects you to the main process on pts/0, so typing exit there ends PID 1 and the container stops. exit in an exec shell only ends that extra shell, and the container keeps running.

Go deeper:

From Quiz: ISLAB / Docker Introduction | Updated: Nov 10, 2026