Listing and Inspecting

Naming, Listing and Inspecting Containers

Scripts need names they can rely on. --name sets one, and Docker 514 refuses a second container with the same name, which stops you starting two copies of a database by accident. Commands accept the name, the ID or a unique ID prefix:

A named container, listed and inspectedShell
docker run -d --name l3-postgres -e POSTGRES_PASSWORD=booknest postgres:18
docker ps --filter name=l3- --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'
docker inspect l3-postgres --format \
  '{{.State.Status}} pid={{.State.Pid}} ip={{.NetworkSettings.Networks.bridge.IPAddress}}'
Output
870bae3a0caea75e39aeff122bf8fa9aa7599b4398aab37cb1c06dc919f07f3e
NAMES         IMAGE         STATUS
l3-postgres   postgres:18   Up Less than a second
running pid=395328 ip=172.17.0.3

docker ps -a includes stopped containers, -q prints bare IDs for scripts, and --filter narrows by name, status, ancestor (image) or label. docker inspect returns the container's full JSON record; --format takes a Go template that extracts single values, here the host PID of PostgreSQL 1,289 's main process and its address on the default bridge network. Other useful paths are .State.ExitCode, .Mounts and .NetworkSettings.Ports.