Docker: Container lifecycle & live changes
10 Docker commands: Container lifecycle & live changes. Click a command to see what each part does.
Docker: Container lifecycle & live changesIndex
- Whole sheet120
- Basics: images & containers11
- Volumes & networks4
- Find & inspect containers7
- Environment variables & container config12
- Software versions inside containers & images9
- Logs & shells5
- Run containers3
- Images4
- Cleanup6
- Docker Compose v27
- Container lifecycle & live changes10
- Builds, multi-platform & moving images11
- Volumes, networks & remote hosts in depth12
- Compose: more commands9
- Swarm mode10
Container lifecycle & live changes10
docker top <container>Processes running inside a containerWhat each part does
docker topps output for the container's processes, as seen from the host (PIDs are host PIDs)<container>name or ID
docker diff <container>Files changed inside a container since it startedWhat each part does
docker difflist files added (A), changed (C) or deleted (D) in the container's writable layer
Tip Handy to find where an app writes data that should be in a volume.
docker kill -s <signal> <container>Send a signal to a containerCautionWhat each part does
docker killsend a signal to the main process (default SIGKILL)-s <signal>e.g. HUP to reload nginx config, TERM for a graceful stop
docker pause <container>; docker unpause <container>Pause and resume a containerWhat each part does
docker pausefreeze all processes (cgroup freezer); memory stays, no CPU useddocker unpauselet them run again
docker wait <container>Wait for a container to exit and get its exit codeWhat each part does
docker waitblock until the container stops, then print its exit code (useful in scripts)
docker update --memory 1g --memory-swap 1g --cpus 1.5 --restart unless-stopped <container>Change memory, CPU or restart policy of a running containerWhat each part does
docker updatechange settings live, no restart--memory 1g --memory-swap 1ghard memory limit; equal swap value means no extra swap--cpus 1.5at most 1.5 CPUs--restart unless-stoppednew restart policy
docker attach --sig-proxy=false <container>Attach to a container's main processWhat each part does
docker attachconnect your terminal to the main process's stdin/stdout--sig-proxy=falseso Ctrl+C doesn't kill the container; detach with Ctrl+P Ctrl+Q
Tip Usually you want docker logs -f or docker exec instead.
docker events --filter container=<container> --since 30mWatch Docker events liveWhat each part does
docker eventsstream of daemon events: create, start, die, oom, health_status, kill...--filter container=<container>only this container (also type=, event=, image=)--since 30minclude events from the last 30 minutes
docker commit -m "<message>" <container> <image>:<tag>Save a container's current state as an imageWhat each part does
docker commitsnapshot the container's filesystem into a new image-m "<message>"commit message<image>:<tag>name for the new image
Tip Good for debugging or forensics; for real images use a Dockerfile.
docker create --name <name> <image>:<tag>Create a container without starting itWhat each part does
docker createcreate the container (pull if needed) but don't run it--name <name>its name; start later with docker start
Nothing matches.
My DevOps Playbook by Angelo John Calleja