Docker Commands Cheat Sheet: The 40 You'll Actually Use
A practical Docker cheat sheet: running and stopping containers, viewing logs, getting a shell inside, building and tagging images, volumes, networks, Docker Compose, and cleaning up disk space — with what each command does in plain English.
The Docker commands you'll use day to day, grouped by job. New to Docker? Start with What is Docker? and Docker image vs container.
Running containers
docker run nginx # run a container (foreground)
docker run -d nginx # run in the background (detached)
docker run -d --name web nginx # give it a name
docker run -d -p 8080:80 nginx # publish port: host 8080 → container 80
docker run -e API_KEY=abc myapp # set an environment variable
docker run --env-file .env myapp # load variables from a file
docker run -v mydata:/data myapp # attach a named volume
docker run -v "$(pwd)":/app myapp # mount the current folder
docker run --rm -it node:24 bash # throwaway interactive shell
docker run -d --restart unless-stopped myapp # restart automatically
Seeing what's running
docker ps # running containers
docker ps -a # all containers, including stopped
docker stats # live CPU/memory per container
docker top web # processes inside a container
docker inspect web # everything about a container (JSON)
docker port web # its published ports
Logs
docker logs web # all logs
docker logs -f web # follow live
docker logs --tail 100 web # last 100 lines
docker logs --since 10m web # last 10 minutes
The first place to look when something's wrong. (Docker container keeps restarting)
Getting inside
docker exec -it web sh # open a shell in a running container (bash if available)
docker exec web ls /app # run one command
docker cp web:/app/log.txt . # copy a file out
docker cp ./config.json web:/app/ # copy a file in
Stopping and removing
docker stop web # graceful stop
docker kill web # immediate stop
docker start web # start a stopped container
docker restart web
docker rm web # remove a stopped container
docker rm -f web # stop and remove
Images
docker images # list images
docker pull postgres:18 # download an image
docker build -t myapp . # build from the Dockerfile here
docker build -t myapp:1.2 --platform linux/amd64 .
docker tag myapp you/myapp:1.2
docker push you/myapp:1.2 # upload to a registry
docker rmi myapp # remove an image
docker history myapp # layers and their sizes
(Dockerfile explained, exec format error)
Volumes
docker volume ls
docker volume create pgdata
docker volume inspect pgdata
docker volume rm pgdata # ⚠ deletes the data
(Docker volumes vs bind mounts)
Networks
docker network ls
docker network create mynet
docker run -d --network mynet --name db postgres:18
docker network inspect mynet
Containers on the same user-defined network reach each other by name. (Container networking internals)
Docker Compose
docker compose up -d # start all services
docker compose up -d --build # rebuild then start
docker compose ps
docker compose logs -f web
docker compose exec db psql -U postgres
docker compose restart web
docker compose pull # update images
docker compose down # stop and remove containers
docker compose down -v # ⚠ also removes volumes
Cleaning up disk space
Docker quietly fills disks with old images, stopped containers and build cache.
docker system df # what's using space
docker container prune # remove stopped containers
docker image prune # remove dangling images
docker image prune -a # remove all unused images
docker builder prune # clear build cache
docker system prune # all of the above (not volumes)
docker system prune -a --volumes # ⚠ everything unused, including volumes
A full disk breaks builds and databases. (No space left on device)
Useful flags to remember
| Flag | Meaning |
|---|---|
-d |
Run in background |
-it |
Interactive terminal |
-p host:container |
Publish a port |
-v src:dest |
Mount a volume or folder |
-e KEY=value |
Environment variable |
--rm |
Remove container when it exits |
--name |
Name the container |
-f |
Follow (logs) / force (rm) |
EasySpawn gives you a server where Docker is installed and ready, with a terminal (and Claude Code) one click away for any of these commands. See how it works or join the waitlist.
Related: What Is Docker? · Docker vs Docker Compose · Dockerfile Explained · Basic Linux Commands
Keep reading
Docker vs Docker Compose: What's the Difference?
Docker runs individual containers; Docker Compose describes and runs a group of containers that work together — your app, its database and a cache — from one YAML file. How they relate, the same setup with and without Compose, and the commands you'll use.
zsh vs bash: What's the Difference and Which Should You Use?
bash and zsh are both shells — the programs that read your terminal commands. Why macOS switched to zsh, the differences you'll actually notice (config files, completion, globbing, arrays), Oh My Zsh, and why scripts should usually still be written for bash.