Tools
Docker Cheat Sheet — Commands Reference
The Docker commands you need for everyday container work, from building images to cleaning up disk space.
Advertisement
Images
docker build -t name:tag .Build an image from the Dockerfile heredocker imagesList local imagesdocker pull nginx:alpineDownload an image from a registrydocker rmi <image>Remove an imagedocker tag src targetGive an image another name/tagRunning containers
docker run -it image shRun interactively with a shelldocker run -d -p 8080:80 imageRun detached, mapping host:container portsdocker run --rm imageAuto-remove the container when it exitsdocker run -e KEY=value imagePass an environment variabledocker run -v $(pwd):/app imageMount the current directory into the containerManaging containers
docker psList running containers (-a for all)docker stop <id>Stop a container gracefullydocker start <id>Start a stopped containerdocker rm <id>Remove a stopped containerdocker exec -it <id> shOpen a shell inside a running containerdocker logs -f <id>Follow a container’s logsCompose
docker compose up -dStart all services in the backgrounddocker compose downStop and remove servicesdocker compose logs -fFollow logs for all servicesdocker compose buildRebuild service imagesdocker compose psList service containersCleanup
docker system pruneRemove stopped containers, unused networks, dangling imagesdocker system prune -a --volumesAggressive cleanup, including volumes (careful)docker volume lsList volumesdocker system dfShow how much disk Docker is using