Table of Common Docker Container Operations
1. Exiting an Interactive Container
When you run a container with-i (interactive) and -t (TTY), typing exit in the shell will stop both the shell and the container:
2. Detaching Without Stopping
To keep the container running after leaving the shell, pressCtrl-p followed by Ctrl-q:
The detach sequence
Ctrl-p + Ctrl-q does not stop the container; it simply returns you to the host shell.3. Executing a One-off Command
To run a single command in an existing container, usedocker exec:
4. Opening an Interactive Shell
When you need to troubleshoot or inspect the environment, start a new shell inside the container:5. Attaching to a Running Container
To reconnect to the container’s initial process (PID 1), use:Exiting the primary shell (PID 1) will stop the container. To avoid unintentionally shutting it down, detach (
Ctrl-p Ctrl-q) instead of exiting.