Skip to content

Docker & Podman: Debug & troubleshoot

Docker & Podman commands for debug & troubleshoot (tags: #debug #performance).

Index
10 items

Docker9

Docker: Show container logs for a time window

Safe

Logs from the last N minutes/hours, e.g. --since 15m or --since 2h.

docker logs --since <duration> <container>
What each part does
  1. docker logsshow a container's output
  2. --since <duration>only lines newer than this: relative (30m, 2h) or a timestamp; pair with --until
  3. <container>container name or ID
Example
$ docker logs --since 15m api

Also known as: logs since

Docker: List containers with status and ports

Safe

All containers (including exited) in a compact table.

docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
What each part does
  1. docker pslist containers
  2. -ainclude stopped ones
  3. --format "table ..."Go template; table adds a header row and aligns columns
  4. {{.Names}}\t{{.Status}}\t{{.Ports}}the columns: name, status (Up / Exited (code)), port mappings, tab separated

Also known as: docker ps · exited containers

Docker: Open a shell inside a container

Safe

Interactive shell in a running container. Use bash if the image has it.

docker exec -it <container> sh
What each part does
  1. docker execrun a command in a running container
  2. -itinteractive + allocate a terminal
  3. <container>container name or ID
  4. shthe shell to start; use bash if the image has it

Also known as: docker exec · shell into container

Docker: Check exit code and OOM kill

Safe

Why did it stop? 137 + OOMKilled=true means the memory limit was hit.

docker inspect <container> --format '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}'
What each part does
  1. docker inspect <container>full JSON details of a container (works on stopped ones too)
  2. --format '...'Go template: print only the fields you ask for
  3. {{.State.ExitCode}}the exit code of the last run (137 = SIGKILL, 143 = SIGTERM)
  4. {{.State.OOMKilled}}true if the kernel killed it for exceeding its memory limit
Example
137 OOMKilled=true

Also known as: exit code 137 · OOMKilled · container keeps restarting

Docker: Show live container resource usage

Safe

One-shot CPU, memory, network and block I/O per container.

docker stats --no-stream
What each part does
  1. docker statsCPU, memory, network and disk I/O per running container
  2. --no-streamprint one snapshot and exit instead of refreshing

Also known as: docker stats · container memory

Docker: Copy a file out of a container

Safe

Grab a config, dump or log file from a container to the current directory.

docker cp <container>:<path> ./
What each part does
  1. docker cpcopy files between a container and the host (works on stopped containers)
  2. <container>:<path>source: a path inside the container
  3. ./destination: the current directory on the host

Also known as: docker cp

Docker: Show disk used by Docker

Safe

Space used by images, containers, local volumes and build cache, and how much is reclaimable.

docker system df
What each part does
  1. docker system dfdisk used by images, containers, volumes and build cache, with how much is reclaimable; add -v for per-item detail

Also known as: docker disk usage · /var/lib/docker full

Docker: Check the base OS of an image

Safe

Tells you which package manager to patch with in the Dockerfile (apt, apk, dnf, microdnf).

docker run --rm --entrypoint cat <image>:<tag> /etc/os-release
What each part does
  1. docker run --rmthrowaway container
  2. --entrypoint catskip the image entrypoint and just run cat
  3. /etc/os-releasedistro name and version

Also known as: image os · base image distro · which distro image

Docker: Print environment variables of a container

Safe

Every env var the running container sees. Stopped container: docker inspect <container> --format '{{range .Config.Env}}{{println .}}{{end}}'.

docker exec <container> env
What each part does
  1. docker exec <container>run a command inside the running container (name or ID)
  2. envprint every environment variable, KEY=value per line; use printenv <VAR> for just one
Example
$ docker exec api env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=4f2a9c1e7b3d
NODE_ENV=production
DATABASE_HOST=db

My note Values passed with -e or --env-file (including secrets) are readable by anyone with docker access. Distroless images have no env binary: use the inspect form.

Also known as: docker print env · docker env vars · show container environment · printenv

Podman1

Podman: List all containers

Safe

Running and exited containers, rootless by default for the current user.

podman ps -a
What each part does
  1. podman pslist containers
  2. -ainclude stopped ones

Also known as: podman ps

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/…