elefcode
← All cheat sheets

Tools

Docker Cheat Sheet — Commands Reference

The Docker commands you need for everyday container work, from building images to cleaning up disk space.

Put it into practice with the matching tool.

Convert docker run to Compose →

Advertisement

Images

docker build -t name:tag .Build an image from the Dockerfile here
docker imagesList local images
docker pull nginx:alpineDownload an image from a registry
docker rmi <image>Remove an image
docker tag src targetGive an image another name/tag

Running containers

docker run -it image shRun interactively with a shell
docker run -d -p 8080:80 imageRun detached, mapping host:container ports
docker run --rm imageAuto-remove the container when it exits
docker run -e KEY=value imagePass an environment variable
docker run -v $(pwd):/app imageMount the current directory into the container

Managing containers

docker psList running containers (-a for all)
docker stop <id>Stop a container gracefully
docker start <id>Start a stopped container
docker rm <id>Remove a stopped container
docker exec -it <id> shOpen a shell inside a running container
docker logs -f <id>Follow a container’s logs

Compose

docker compose up -dStart all services in the background
docker compose downStop and remove services
docker compose logs -fFollow logs for all services
docker compose buildRebuild service images
docker compose psList service containers

Cleanup

docker system pruneRemove stopped containers, unused networks, dangling images
docker system prune -a --volumesAggressive cleanup, including volumes (careful)
docker volume lsList volumes
docker system dfShow how much disk Docker is using

Related guides

More cheat sheets