Yash Verma / Cloud runbook

Docker commands

15 commands from the cloud runbook. Fill in a placeholder once and every command uses it.

Remove all Docker containers, images and volumes

Stops running containers, then removes stopped containers, unused images, networks, build cache and volumes.

Caution. Destructive: deletes every unused volume, database data included. Leave out --volumes to keep volumes.

docker ps -q | xargs -r docker stop && docker system prune -a --volumes -f

cleanup, nuke, prune

Open a shell in a container

Starts an interactive shell inside a running container.

docker exec -it <container-id> /bin/sh

Use /bin/bash if the image has it.

exec, shell

Live container metrics

Shows a live stream of CPU/Memory usage.

docker stats

metrics, performance

Build image without cache

Forces a completely fresh docker build bypassing all cached layers.

docker build --no-cache -t <image-name>:<tag> .

build, cache

Remove dangling images

Removes dangling images: untagged <none> layers left behind by rebuilds.

docker image prune -f

cleanup, images

Start Compose services in the background

Starts all services defined in a docker-compose.yml in the background.

docker compose up -d

compose, daemon

Get container IP

Extracts the internal IP address of a running docker container.

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container-id>

inspect, ip

Follow container logs

Tails the logs of a docker container continuously.

docker logs -f <container-id>

logs, tail

List volumes

Lists all Docker volumes on the host.

docker volume ls

volume, storage

List networks

Lists all Docker networks.

docker network ls

network, list

Tag an image

Tags a local image with a new name for pushing to a registry.

docker tag <image-id> <registry>/<repo>:<tag>

tag, registry

Push image to registry

Pushes a tagged image to a container registry.

docker push <registry>/<repo>:<tag>

push, registry

Copy files from container

Copies a file from inside a running container to the host.

docker cp <container-id>:/path/in/container /local/path

copy, files

View image layer history

Shows the build history and layer sizes of a Docker image.

docker history <image-name>

history, layers, debug

Save an image to a tar file

Writes an image to a tar file for offline transfer. Load it on the other host with docker load -i image.tar.

docker save -o image.tar <image-name>:<tag>

save, load, offline