All Cheatsheets

Docker Cheatsheet

Essential Docker commands for containers, images, networking, volumes, and Docker Compose.

6 sections57 commandsClick any row to copy

Container Basics

docker run -d -p 8080:80 --name myapp nginx
docker run -it ubuntu bash
docker run --rm -e ENV=prod alpine sh
docker ps
docker ps -a
docker stop myapp
docker kill myapp
docker rm myapp
docker rm -f myapp
docker logs -f myapp
docker exec -it myapp bash
docker inspect myapp
docker stats
docker cp myapp:/app/file.txt .

Run container in background, map port 8080→80

Interactive shell inside container

Auto-remove on exit, set env variable

List running containers

List all containers (including stopped)

Gracefully stop container

Force stop container immediately

Remove stopped container

Force remove running container

Follow container logs in real time

Open shell inside running container

Detailed JSON info about container

Live CPU/memory/network usage

Copy file from container to host

Images

docker images
docker pull nginx:1.25-alpine
docker push myrepo/myapp:v1.0
docker build -t myapp:v1.0 .
docker build --no-cache -t myapp:latest .
docker tag myapp:latest myrepo/myapp:v1.0
docker rmi myapp:latest
docker image prune -a
docker history myapp:latest
docker save myapp:latest | gzip > myapp.tar.gz
docker load < myapp.tar.gz

List all local images

Pull specific image tag

Push image to registry

Build image from Dockerfile in current dir

Build without using cache layers

Tag image for registry push

Remove local image

Remove all unused images

Show image layer history + sizes

Export image to compressed file

Import image from file

Volumes

docker volume ls
docker volume create mydata
docker volume inspect mydata
docker volume rm mydata
docker volume prune
docker run -v mydata:/app/data nginx
docker run -v $(pwd):/app nginx
docker run -v $(pwd):/app:ro nginx

List all volumes

Create named volume

Volume details and mount path

Remove volume

Remove all unused volumes

Mount named volume to container

Bind mount current directory

Bind mount as read-only

Networking

docker network ls
docker network create mynet
docker network inspect mynet
docker run --network mynet --name api myapp
docker network connect mynet myapp
docker network disconnect mynet myapp
docker network rm mynet

List all networks

Create custom bridge network

Inspect network and connected containers

Connect container to network

Connect running container to network

Disconnect container from network

Remove network

Docker Compose

docker compose up -d
docker compose up -d --build
docker compose down
docker compose down -v
docker compose ps
docker compose logs -f
docker compose logs -f web
docker compose exec web bash
docker compose restart web
docker compose up -d --scale web=3
docker compose pull
docker compose config

Start all services in background

Rebuild images then start

Stop and remove containers

Stop + remove containers and volumes

List running services

Follow logs from all services

Follow logs from specific service

Shell into service container

Restart specific service

Scale service to 3 replicas

Pull latest images for all services

Validate and view merged compose config

System & Cleanup

docker system df
docker system prune
docker system prune -a --volumes
docker container prune
docker image prune

Show disk usage by images, containers, volumes

Remove all stopped containers, unused networks/images

Nuclear cleanup — remove everything unused

Remove all stopped containers

Remove dangling (untagged) images