Developer Reference
Docker CLI Cheat Sheet
Quick reference for Docker containers, images, volumes, and networks.
Docker revolutionizes how we deploy applications. This cheat sheet gives you instant access to the commands you need for managing containers, building images, and inspecting volumes.
Visual Guide
Docker Production Tips
- Use Multi-stage Builds: Keep your final image small by discarding build dependencies.
- Tag Images Explicitly: Avoid `latest`. Use semantic versioning like `v1.2.0`.
- Don't Run as Root: Create a specific user in your Dockerfile for security.
- Don't Persist Data in Containers: Always use Volumes for database data.
Containers
Create and start a container
docker run
List running containers
docker ps
List all containers (running and stopped)
docker ps -a
Remove a container
docker rm [container]
Images
List available images
docker images
Remove an image
docker rmi [image]
Build
Build an image from a Dockerfile
docker build -t [tag] .
Compose
Start services in detached mode
docker compose up -d
Stop and remove resources
docker compose down
Debugging
Access container shell
docker exec -it [id] bash
View container logs
docker logs [id]
Volumes
List volumes
docker volume ls
Networking
List networks
docker network ls
Create a new network
docker network create [name]
Connect container to network
docker network connect [net] [cont]
System
Show docker disk usage
docker system df
Cleanup
Remove all unused data (careful!)
docker system prune -a
Management
Copy files from container
docker cp [cont]:[path] [local]
Create new image from container
docker commit [cont] [image]
Kill a running container
docker kill [id]
Inspection
Return low-level information on objects
docker inspect [id]
Monitoring
Display the running processes of a container
docker top [id]
Whether you are debugging a crashing container or cleaning up unused images to save disk space, these Docker commands are your daily drivers.