The snippet library.
Small, practical examples. Search by task or narrow things down below.
Find a named container in the created state
Docker / Compose: Combine name and status filters to narrow a listing.
Docker / Compose✓ Tested
Force a disposable container to stop
Docker / Compose: kill sends SIGKILL by default without a graceful shutdown interval.
Docker / Compose✓ Tested
Inspect the exit code of a completed process
Docker / Compose: Container state retains the exit code until the container is removed.
Docker / Compose✓ Tested
List only containers belonging to a label
Docker / Compose: A label filter selects explicitly tagged resources.
Docker / Compose✓ Tested
Rename a container without recreating it
Docker / Compose: rename updates the container name while preserving its identity.
Docker / Compose✓ Tested
Restart an existing container
Docker / Compose: restart starts the same container again while retaining its writable layer.
Docker / Compose✓ Tested
Start an existing container and attach to its output
Docker / Compose: create records the command; start with attach runs that existing container.
Docker / Compose✓ Tested
Stop a running container gracefully
Docker / Compose: stop sends the configured stop signal and waits before forcing termination.
Docker / Compose✓ Tested
Verify that a one-off container was removed
Docker / Compose: An automatically removed container no longer appears in an exact-name listing.
Docker / Compose✓ Tested
Wait for a container to exit
Docker / Compose: wait blocks until the container stops and prints its exit code.
Docker / Compose✓ Tested