Skip to content

Docker: Container lifecycle & live changes

10 Docker commands: Container lifecycle & live changes. Click a command to see what each part does.

Index
10 items
Click a command to see what each part does.

Container lifecycle & live changes10

  • docker top <container>Processes running inside a container

    What each part does

    1. docker topps output for the container's processes, as seen from the host (PIDs are host PIDs)
    2. <container>name or ID
  • docker diff <container>Files changed inside a container since it started

    What each part does

    1. 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 containerCaution

    What each part does

    1. docker killsend a signal to the main process (default SIGKILL)
    2. -s <signal>e.g. HUP to reload nginx config, TERM for a graceful stop
  • docker pause <container>; docker unpause <container>Pause and resume a container

    What each part does

    1. docker pausefreeze all processes (cgroup freezer); memory stays, no CPU used
    2. docker unpauselet them run again
  • docker wait <container>Wait for a container to exit and get its exit code

    What each part does

    1. 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 container

    What each part does

    1. docker updatechange settings live, no restart
    2. --memory 1g --memory-swap 1ghard memory limit; equal swap value means no extra swap
    3. --cpus 1.5at most 1.5 CPUs
    4. --restart unless-stoppednew restart policy
  • docker attach --sig-proxy=false <container>Attach to a container's main process

    What each part does

    1. docker attachconnect your terminal to the main process's stdin/stdout
    2. --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 live

    What each part does

    1. docker eventsstream of daemon events: create, start, die, oom, health_status, kill...
    2. --filter container=<container>only this container (also type=, event=, image=)
    3. --since 30minclude events from the last 30 minutes
  • docker commit -m "<message>" <container> <image>:<tag>Save a container's current state as an image

    What each part does

    1. docker commitsnapshot the container's filesystem into a new image
    2. -m "<message>"commit message
    3. <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 it

    What each part does

    1. docker createcreate the container (pull if needed) but don't run it
    2. --name <name>its name; start later with docker start

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…