Docker Run, Attach, and Exec: How They Work Under the Hood
Metadata
- URL: https://labs.iximiuz.com/tutorials/docker-run-vs-attach-vs-exec#docker-architecture-overview
- Author: Ivan Velichko (iximiuz)
- Date Ingested: 2026-05-03
Summary
A deep dive into the internals of the Docker run, attach, and exec commands, explaining the layered architecture (CLI → dockerd → containerd → shim → container) and how stdio streams are managed.
Key Takeaways
- Layered Architecture:
terminal <-> docker CLI <-> dockerd <-> containerd <-> shim <-> application (container). - Docker Run: Not a parent of the container. It establishes a relay to simulate a foreground process.
- Shim Component: Acts as a buffer between the container manager and the container process, handling stdio and signals even if the manager restarts.
- Run vs Attach vs Exec:
run: Creates and starts a new container, setting up the relay.attach: Joins the stdio streams of an existing running container’s primary process (PID 1).exec: Starts a new process inside an existing container.
Reference Content
(See original article for visual diagrams and hands-on terminal examples)