A Docker commands cheat sheet is a quick reference for the CLI commands you use to run and debug containers, build and share images, manage volumes and networks, drive Docker Compose and clean up disk space. Search 74 commands by name or task, copy a working example and see which ones delete data before you run them. Nothing here runs on your machine.
Showing 74 of 74 commands
Run & manage containers
docker run
Create and start a new container from an image. Pulls the image first if it is missing.
Syntax: docker run [options] image [command]
-d
run in the background (detached)
-p 8080:80
publish host port 8080 to container port 80
--name web
give the container a name
-e KEY=value
set an environment variable
-v ./data:/data
mount a host folder or volume
--rm
delete the container when it exits
$ docker run -d --name web -p 8080:80 nginx
docker run -it
Start a container with an interactive terminal, for example a throwaway shell.
Syntax: docker run -it [--rm] image [shell]
-i
keep stdin open
-t
allocate a terminal
--rm
remove it when you exit
--entrypoint sh
override the image entrypoint
$ docker run -it --rm ubuntu bash
docker ps
List running containers with their IDs, images, ports and status.
Syntax: docker ps [options]
-a
include stopped containers
-q
print only container IDs
--filter status=exited
filter by status, name, label and more
--format
custom output with a Go template
$ docker ps -a
docker stop
Stop a running container gracefully: sends SIGTERM, then SIGKILL after a timeout.
Syntax: docker stop [-t seconds] container...
-t 30
wait 30 seconds before killing (default 10)
$ docker stop web
docker start
Start one or more stopped containers.
Syntax: docker start [options] container...
-a
attach to output
-i
attach stdin
$ docker start web
docker restart
Stop and start a container again.
Syntax: docker restart [-t seconds] container...
-t
seconds to wait before killing
$ docker restart web
docker kill
Stop a container immediately with SIGKILL, or send another signal.
Syntax: docker kill [-s signal] container...
-s HUP
send a different signal, such as HUP to reload
$ docker kill web
Careful: SIGKILL gives the process no chance to flush data or close connections. Try docker stop first.
docker rm
Delete one or more stopped containers.
Syntax: docker rm [options] container...
-f
force-remove a running container
-v
also remove its anonymous volumes
$ docker rm web
Careful: Anything written inside the container and not in a volume is lost. With -f a running container is killed first; with -v its anonymous volumes are deleted.
Careful: Copying into a container overwrites files with the same name without asking.
volume backup
Back up a volume to a tar file using a throwaway container.
Syntax: docker run --rm -v volume:/data -v "$PWD":/backup alpine tar ...
--rm
remove the helper container afterwards
$ docker run --rm -v pgdata:/data -v "$PWD":/backup alpine tar czf /backup/pgdata.tgz -C /data .
Networks & ports
docker network ls
List networks. Default ones are bridge, host and none.
Syntax: docker network ls [options]
-q
IDs only
$ docker network ls
docker network create
Create a user-defined network so containers can reach each other by name.
Syntax: docker network create [options] name
--driver bridge
network driver (default bridge)
--subnet 172.28.0.0/16
choose the subnet
$ docker network create appnet
docker network connect
Attach a running container to a network. disconnect does the opposite.
Syntax: docker network connect network container
--alias db
extra DNS name on that network
$ docker network connect appnet web
docker network inspect
Show a network's subnet, gateway and connected containers.
Syntax: docker network inspect network...
$ docker network inspect appnet
docker network rm
Delete one or more networks.
Syntax: docker network rm network...
prune
docker network prune deletes all unused networks
$ docker network rm appnet
docker run -p
Publish container ports on the host so you can reach them from outside.
Syntax: docker run -p [ip:]host:container[/udp] image
-p 8080:80
host 8080 to container 80
-p 127.0.0.1:5432:5432
only on localhost
-P
publish every exposed port to random host ports
--network host
share the host network (Linux)
$ docker run -d -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=secret postgres:17
Careful: -p 5432:5432 listens on every host interface and Docker's firewall rules can bypass ufw. Bind to 127.0.0.1 for services that should stay private.
Docker Compose
docker compose up
Create and start every service in compose.yaml.
Syntax: docker compose up [options] [service...]
-d
run in the background
--build
rebuild images first
--force-recreate
recreate containers even if unchanged
--remove-orphans
remove containers for services no longer in the file
$ docker compose up -d --build
docker compose down
Stop and remove the project's containers and networks.
Syntax: docker compose down [options]
-v
also delete named and anonymous volumes
--rmi all
also delete images
--remove-orphans
remove containers not in the file
$ docker compose down
Careful: down -v deletes the project's volumes, including database data. Plain down keeps volumes.
Careful: Never pass a password with -p on the command line; it lands in shell history. Use --password-stdin with a token.
docker logout
Remove stored credentials for a registry.
Syntax: docker logout [registry]
$ docker logout ghcr.io
docker push
Upload a tagged image to a registry.
Syntax: docker push image[:tag]
-a
push every tag of the repository
$ docker push ghcr.io/acme/myapp:1.4.0
docker manifest inspect
Show which platforms a remote image supports without pulling it.
Syntax: docker manifest inspect image[:tag]
-v
verbose, with digests per platform
$ docker manifest inspect node:22
Cleanup & system
docker system df
Show how much disk space images, containers, volumes and build cache use.
Syntax: docker system df [-v]
-v
details per image, container and volume
$ docker system df
docker system prune
Free disk space by deleting stopped containers, unused networks, dangling images and build cache in one go.
Syntax: docker system prune [options]
-a
also delete every image not used by a container
--volumes
also delete unused volumes
-f
do not ask for confirmation
$ docker system prune
Careful: Stopped containers are deleted with their data. Adding --volumes deletes unused volumes such as a database you stopped; -a removes images you will have to pull again. Run docker system df first.
docker container prune
Delete every stopped container.
Syntax: docker container prune [options]
-f
do not ask
--filter until=24h
only containers created over 24 hours ago
$ docker container prune --filter until=24h
Careful: Files written inside those containers outside volumes are lost.
remove all containers
Stop and delete every container on this machine.
Syntax: docker rm -f $(docker ps -aq)
-aq
IDs of all containers, running or not
$ docker rm -f $(docker ps -aq)
Careful: This kills and deletes every container, including ones from other projects. List them with docker ps -a first.
docker info
Show daemon details: storage driver, container counts, CPUs, memory and warnings.
Syntax: docker info [--format]
--format
pick one field
$ docker info
docker version
Show the client and server (engine) versions.
Syntax: docker version
--format
pick one field
$ docker version
docker context
Switch which Docker engine the CLI talks to, such as a remote host over SSH.
Syntax: docker context ls | create | use name
create --docker host=ssh://user@host
add a remote engine
use default
switch back to local
$ docker context use default
How to use this Docker command list
1. Search by command or task
Type a command such as logs, or a task such as shell, disk space or port.
2. Filter by category
Pick a category such as Volumes or Docker Compose to narrow the list.
3. Read the syntax and flags
Check the syntax line, the common flags and any Careful note before you run it.
4. Copy the example
Copy the example, change the container, image or volume names to yours and run it.
Docker commands FAQ
What are the most used Docker commands?
docker run starts a container, docker ps lists them, docker logs and docker exec help you debug, docker stop and docker rm stop and delete them, docker build and docker pull get images, and docker compose up -d starts a whole multi-container app. Learn these first.
How do I get a shell inside a running container?
Run docker exec -it <container> sh, or bash if the image has it. With Compose, use docker compose exec <service> sh. Leaving the shell does not stop the container.
How do I free disk space used by Docker?
Run docker system df to see what uses space, then docker system prune to delete stopped containers, unused networks, dangling images and build cache. docker builder prune clears only the build cache. Add --volumes only if you are sure no data in unused volumes is needed.
What is the difference between docker compose down and down -v?
docker compose down stops and removes the project's containers and networks but keeps volumes, so database data survives. docker compose down -v also deletes the volumes and their data.
Is it docker-compose or docker compose?
Use docker compose (with a space). It is Compose v2, built into the Docker CLI. The old docker-compose v1 Python tool is no longer supported, though most commands and compose files work the same.
Which Docker commands delete data?
docker rm, docker volume rm, docker volume prune, docker compose down -v, docker system prune --volumes and docker rm -f $(docker ps -aq) can all delete data with no undo. This cheat sheet marks each one with a Careful note.
Automate the container chores you repeat
Rebuilding, migrating, checking logs and pruning the same way every week? Tornic turns those steps into deterministic multi-step workflows that run on the Claude Code, Codex or Cursor CLI you already pay for.