Docker Cheatsheet

This cheatsheet provides a comprehensive and practical reference for common Docker commands. It covers images, containers, volumes, networks, Docker Compose, command combos, and more. Use it to boost your productivity in containerization and DevOps workflows.

Images

docker images
List all local images
docker pull [image]
Download an image from a registry
docker rmi [image]
Remove an image
docker tag [image] [new_image]
Tag an image
docker build -t [name] .
Build an image from Dockerfile
docker history [image]
Show history of an image
docker save -o [file.tar] [image]
Save image to a tar archive
docker load -i [file.tar]
Load image from a tar archive

Containers

docker ps
List running containers
docker ps -a
List all containers
docker run [image]
Run a container from an image
docker run -d [image]
Run in detached mode
docker run -p 8080:80 [image]
Map port 8080 to 80
docker run --name [name] [image]
Assign a name to the container
docker exec -it [container] bash
Run a bash shell in a running container
docker stop [container]
Stop a running container
docker start [container]
Start a stopped container
docker restart [container]
Restart a container
docker rm [container]
Remove a container
docker logs [container]
View container logs
docker inspect [container]
View detailed info about a container
docker cp [container]:/src /dest
Copy files from container to host
docker pause [container]
Pause all processes in a container
docker unpause [container]
Unpause a container

Volumes

docker volume ls
List all volumes
docker volume create [name]
Create a new volume
docker volume inspect [name]
View details of a volume
docker volume rm [name]
Remove a volume
docker run -v [vol]:/data [image]
Mount a volume in a container

Networks

docker network ls
List all networks
docker network create [name]
Create a new network
docker network inspect [name]
View details of a network
docker network rm [name]
Remove a network
docker run --network [name] [image]
Connect a container to a network

Docker Compose

docker-compose up
Start services defined in docker-compose.yml
docker-compose up -d
Start in detached mode
docker-compose down
Stop and remove containers, networks, images, and volumes
docker-compose build
Build or rebuild services
docker-compose logs
View output from services
docker-compose exec [service] bash
Run a command in a running service container
docker-compose ps
List containers

Command Combos

docker ps -aq | xargs docker rm -f
Remove all containers
docker images -q | xargs docker rmi -f
Remove all images
docker volume ls -q | xargs docker volume rm
Remove all volumes
docker network ls -q | xargs docker network rm
Remove all networks
docker system prune -a
Remove all unused data
docker exec -it $(docker ps -q | head -1) bash
Open bash in the first running container
docker-compose down -v
Remove containers and volumes with compose
docker run --rm -it [image] bash
Run a container and remove it after exit
docker logs -f [container]
Follow logs output

Categories

  • Images

    Commands for managing Docker images, including pulling, building, tagging, and removing images.

  • Containers

    Commands for running, stopping, inspecting, and managing containers.

  • Volumes

    Commands for creating, inspecting, and mounting Docker volumes.

  • Networks

    Commands for creating, inspecting, and managing Docker networks.

  • Docker Compose

    Commands for managing multi-container applications with Docker Compose.

  • Command Combos

    Powerful multi-step workflows and advanced usage patterns for real-world scenarios.

Features

  • Quick search functionality
  • Organized by categories
  • Clear command descriptions
  • Common and advanced use cases covered
  • Easy to copy commands
  • Responsive design
  • Perfect for quick reference