Quick reference for Docker. Run docker --help or docker <command> --help for full flag lists.
| Command | What it does | Typical usage |
|---|---|---|
| docker ps | Lists running containers | Confirm what is actually running right now |
| docker ps -a | Lists all containers, including stopped ones | See the full picture — including failed or exited containers |
| docker logs -f <name> | Streams container output to your terminal | Debug a container; see why it started or is failing |
| docker exec -it <name> sh | Opens an interactive shell inside a running container | Inspect files, test connectivity, run one-off commands |
| docker run -d --name X -p H:C image:tag | Creates and starts a named, port-mapped, detached container | The standard way to spin up a service — use a specific tag, not latest |
| docker stop <name> | Gracefully stops a running container (SIGTERM, then SIGKILL) | Shut down a container cleanly |
| docker start <name> | Starts a stopped container | Bring back a container you already created |
| docker rm <name> | Removes a stopped container | Clean up finished test containers |
| docker system prune | Removes all unused containers, networks, and dangling images | Reclaim disk space after a session of testing |
| Command | What it does | Typical usage |
|---|---|---|
| docker image ls | Lists local images — repository, tag, image ID, size | Check what is already downloaded on this machine |
| docker container ls / docker ps | Lists running containers with port mappings and uptime | See what is running right now |
| docker ps -a | Lists all containers including stopped and exited ones | Find old containers you forgot about; see exit codes |
| docker logs <name> | Dumps the container's stdout/stderr output | See what happened when a container started or crashed |
| docker logs -f <name> | Follows (streams) container output in real time | Live tail — leave it running to watch the app |
| docker inspect <name> | Dumps full JSON metadata — ports, mounts, env vars, network, health | Check the actual port bindings, env vars, and mount paths |
| docker stats | Live CPU, memory, network, and disk I/O per container | Monitor resource usage across all running containers |
| docker top <name> | Shows processes running inside a container | Check what is actually running inside, like a container-scoped ps |
| docker port <name> | Lists the container's port mappings | Confirm which host port a container is actually bound to |
latest.
-p 8080:80
KEY=VALUE per line)
sh always works; use this first
Dockerfile in the current directory
docker login for Docker Hub or docker login ghcr.io for GitHub Container Registry.
| Command | What it does | Typical usage |
|---|---|---|
| docker compose up -d | Builds, creates, and starts all services; -d keeps them in the background |
Start the full stack defined in compose.yaml |
| docker compose ps | Lists containers in this Compose project with their status | Check the health of the whole stack at a glance |
| docker compose logs -f | Streams logs from all services into one terminal | Watch the whole app — useful during debugging |
| docker compose logs -f <svc> | Streams logs from one named service | Focus on a specific container when the full stream is too noisy |
| docker compose down | Stops and removes containers and the project's network | Tear down cleanly without leaving containers behind |
| docker compose down -v | Also removes named volumes declared in the Compose file | Full clean teardown — wipes database volumes too |
| docker compose exec <svc> sh | Opens a shell in a running Compose service container | Debug a specific service — same as docker exec -it |
| docker compose restart <svc> | Restarts one service without touching the others | Pick up a config change without tearing down the whole stack |
| docker compose build | Rebuilds images for services that have a build: block |
Pre-build before running, or after changing a Dockerfile |
| docker compose pull | Pulls the latest version of all third-party images | Update external images like databases before bringing the stack up |
docker run is for one container at a time. docker compose is for a small app made of multiple containers that need to find each other by service name.
image:latest in anything important is asking for a surprise upgrade. Pull the exact tag you tested with, then run that same tag.
docker logs <name> is the first thing to run — the exit code and last lines will almost always tell you why.
--rm means the container cleans itself up automatically on exit — no manual docker rm needed.
docker inspect <name> tells you the ground truth — don't guess from the run command.
exec -it <name> sh first — it works in every image. bash only works in images that include it (Debian/Ubuntu-based ones typically do; Alpine doesn't by default).
docker rm does not remove its named volumes — you need docker volume prune or docker compose down -v to wipe them.
docker system prune is safe for cleaning up unused resources. If you really need space back, docker system prune -a also removes all images not currently used by a running container — this means next run will re-pull.
db:5432, not localhost:5432.