Docker exec vs Docker attach
docker exec starts a brand new process inside an already-running container. It does not touch the container’s main process (PID 1), and exiting the exec session does not stop the container. This is the normal way to get a shell or run one-off commands.
Example: you have an nginx container running as the main process. You want to inspect its config or check logs from inside the container:
docker exec -it my-nginx bash
cat /etc/nginx/nginx.conf
exit
The nginx container keeps running after you exit.
docker attach connects your terminal to the standard input/output/error of the container’s main process (PID 1). This is useful when the container was started with an interactive process, like a shell.
Example:
docker run -it --name my-shell ubuntu bash
Then later you can reattach:
docker attach my-shell
If the main process is an interactive shell and you type exit, the shell exits, PID 1 terminates, and the container stops. To detach without stopping it, use the escape sequence: Ctrl+P then Ctrl+Q.
In short: use exec for maintenance or side tasks; use attach to reconnect to an interactive main process.
Docker wait vs Docker update
docker wait blocks until a container stops, then prints the container’s exit code. It does not start or stop anything itself.
Example in a script or CI pipeline:
docker run -d --name job my-job
docker wait job
echo "Job finished with exit code $?"
This is useful when you need to run a container and then take the next step only after it finishes, without polling docker ps.
docker update changes resource or configuration settings on an existing container, typically CPU and memory limits. It works on running containers without recreating them.
Example: an application container already running needs more memory:
docker update --memory 1g --cpus 2 my-app
You would use docker update when you need to adjust live resource limits or restart policy without destroying and recreating the container.
So: docker wait is for waiting on completion and getting the exit code; docker update is for modifying container configuration after creation.