Docker Cheat Sheet 2026 — All Commands in One Page
This is the complete Docker reference for 2026. All essential commands in one place. Versions covered: Docker Engine 29+, Docker Compose v2 (Compose Specification v5). Container Commands # Run a container docker run nginx # Run in detached mode (background) docker run -d nginx # Run interactively with a shell docker run -it ubuntu:24.04 bash # Run and remove when stopped docker run --rm nginx # Run with a name docker run --name mywebserver nginx # Run with port mapping (host:container) docker run -p 8080:80 nginx # Run with environment variables docker run -e APP_ENV=production myapp:1.0 # Run with environment file docker run --env-file .env myapp:1.0 # Run with volume docker run -v mydata:/data nginx # Run with bind mount docker run -v /host/path:/container/path nginx # Run with resource limits docker run --memory 512m --cpus 1.0 myapp:1.0 # Run as non-root user docker run --user 1001:1001 myapp:1.0 # Run with read-only filesystem docker run --read-only myapp:1.0 # Run with network docker run --network mynetwork myapp:1.0 # Run with restart policy docker run --restart unless-stopped nginx # List running containers docker ps # List all containers (including stopped) docker ps -a # Stop a container (SIGTERM) docker stop mywebserver # Kill a container (SIGKILL) docker kill mywebserver # Start a stopped container docker start mywebserver # Restart a container docker restart mywebserver # Remove a stopped container docker rm mywebserver # Force-remove a running container docker rm -f mywebserver # Remove all stopped containers docker container prune # View container logs docker logs mywebserver # Follow logs in real time docker logs -f mywebserver # Show last 50 lines docker logs --tail 50 mywebserver # Execute a command in a running container docker exec -it mywebserver bash # Copy files to/from a container docker cp mywebserver:/etc/nginx/nginx.conf ./nginx.conf docker cp ./nginx.conf mywebserver:/etc/nginx/nginx.conf # Inspect container details (JSON) docker inspect mywebserver # View real-time resource usage docker stats # View stats for one container docker stats mywebserver # View running processes inside a container docker top mywebserver Image Commands # Pull an image from Docker Hub docker pull nginx # Pull specific version docker pull nginx:1.27 # List local images docker images # Build an image from Dockerfile docker build -t myapp:1.0 . # Build from specific Dockerfile docker build -f Dockerfile.prod -t myapp:prod . # Build with build args docker build --build-arg APP_VERSION=2.0 -t myapp:2.0 . # Tag an image docker tag myapp:1.0 myapp:latest docker tag myapp:1.0 kemalcodes/myapp:1.0 # Push to Docker Hub docker push kemalcodes/myapp:1.0 # Remove an image docker rmi nginx # Remove all unused images docker image prune # Remove all unused images (including tagged but not referenced) docker image prune -a # View image history (layers) docker history nginx # Inspect image details (JSON) docker inspect nginx # Save image to tar file docker save myapp:1.0 -o myapp.tar # Load image from tar file docker load -i myapp.tar Volume Commands # Create a named volume docker volume create mydata # List all volumes docker volume ls # Inspect a volume docker volume inspect mydata # Remove a volume docker volume rm mydata # Remove all unused volumes docker volume prune Network Commands # List all networks docker network ls # Create a network docker network create mynetwork # Create with specific driver docker network create --driver bridge mynetwork # Inspect a network docker network inspect mynetwork # Connect a container to a network docker network connect mynetwork mycontainer # Disconnect a container from a network docker network disconnect mynetwork mycontainer # Remove a network docker network rm mynetwork # Remove all unused networks docker network prune Docker Compose Commands Always use docker compose (v2 plugin), not docker-compose (v1, deprecated). ...