Skip to content

Docker: Find & inspect containers

7 Docker commands: Find & inspect containers. Click a command to see what each part does.

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

Find & inspect containers7

  • docker ps -a | grep <container-id>Find a container by ID or name in the full list

    What each part does

    1. docker pslist containers (running only by default)
    2. -a--all: include stopped / exited containers too
    3. |pipe the table into grep
    4. grep <container-id>keep only the row that contains that ID (a prefix like 3f2a is enough) or name

    Tip Built-in alternative without grep: docker ps -a --filter id=<container-id> (or --filter name=<name>).

  • docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"Only running containers, compact table

    What each part does

    1. docker psrunning containers
    2. --format "table …"Go template output; "table" adds column headers
    3. {{.Names}} {{.Status}} {{.Ports}}fields to show; \t separates columns
  • docker ps -a --filter status=exited --filter name=<name>Filter containers by state, name or image

    What each part does

    1. -aall containers
    2. --filter status=exitedonly exited ones (also: running, paused, restarting…)
    3. --filter name=<name>name contains <name>. Repeating --filter combines them
  • docker ps -qJust the IDs (for scripting)

    What each part does

    1. -q--quiet: print only container IDs, one per line
  • docker inspect --format '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}' <container>Why did it stop? Exit code and OOM

    What each part does

    1. docker inspect <container>full JSON details of the container
    2. --format '…'Go template: print only the fields you ask for
    3. {{.State.ExitCode}}0 = clean exit, 137 = killed (often out of memory), 143 = SIGTERM
    4. {{.State.OOMKilled}}true if the kernel killed it for exceeding its memory limit
  • docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' <container>Container IP address

    What each part does

    1. range .NetworkSettings.Networksloop over every network the container is attached to
    2. {{.IPAddress}}print its IP on that network
  • docker stats --no-streamLive CPU / memory per container

    What each part does

    1. docker statsresource usage of running containers
    2. --no-streamprint one snapshot and exit instead of refreshing

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