Ad 320×100
Developer

Docker Cheat Sheet

Quick reference for Docker commands — containers, images, volumes, and compose

docker run <image>

Create and start a container from an image

docker run -d --name web -p 8080:80 nginx

Run container detached with name and port mapping

docker run -it ubuntu bash

Run container interactively with a shell

docker run --rm <image>

Run container and auto-remove on exit

docker run -v /host:/container <image>

Run with a bind mount

docker run -e VAR=value <image>

Run with an environment variable

docker run --env-file .env <image>

Run with environment variables from a file

docker run --restart unless-stopped <image>

Auto-restart container unless manually stopped

docker ps

List running containers

docker ps -a

List all containers (including stopped)

docker start <container>

Start a stopped container

docker stop <container>

Gracefully stop a running container

docker restart <container>

Restart a container

docker rm <container>

Remove a stopped container

docker rm -f <container>

Force remove a running container

docker rename old_name new_name

Rename a container

docker pause <container>

Pause all processes in a container

docker unpause <container>

Unpause a paused container

docker port <container>

List port mappings for a container

docker images

List all local images

docker images -a

List all images including intermediate layers

docker pull <image>:<tag>

Download an image from a registry

docker push <image>:<tag>

Upload an image to a registry

docker rmi <image>

Remove a local image

docker rmi $(docker images -q -f dangling=true)

Remove all dangling images

docker tag <image> <repo>:<tag>

Create a tag pointing to an image

docker history <image>

Show the history/layers of an image

docker save -o image.tar <image>

Save image to a tar archive

docker load -i image.tar

Load image from a tar archive

docker image inspect <image>

Display detailed image information as JSON

docker volume create <name>

Create a named volume

docker volume ls

List all volumes

docker volume inspect <name>

Show detailed information about a volume

docker volume rm <name>

Remove a volume

docker volume prune

Remove all unused volumes

docker run -v mydata:/data <image>

Mount a named volume into a container

docker run -v $(pwd):/app <image>

Bind mount current directory into container

docker run --mount type=tmpfs,dst=/tmp <image>

Mount a tmpfs (in-memory) volume

docker network create <name>

Create a new network

docker network create --driver bridge mynet

Create a bridge network

docker network ls

List all networks

docker network inspect <name>

Show detailed information about a network

docker network rm <name>

Remove a network

docker network connect <network> <container>

Connect a running container to a network

docker network disconnect <network> <container>

Disconnect a container from a network

docker network prune

Remove all unused networks

docker run --network=mynet <image>

Run container attached to a specific network

docker compose up -d

Start all services in detached mode

docker compose down

Stop and remove all services, networks

docker compose down -v

Stop and remove services, networks, AND volumes

docker compose build

Build or rebuild all service images

docker compose build --no-cache

Build without using cache

docker compose ps

List running compose services

docker compose logs -f <service>

Follow logs of a specific service

docker compose logs --tail 50

Show last 50 lines of logs

docker compose exec <service> bash

Open a shell in a running service

docker compose run <service> <cmd>

Run a one-off command in a new container

docker compose pull

Pull latest images for all services

docker compose restart <service>

Restart a specific service

docker compose config

Validate and display the resolved compose config

docker compose up -d --scale web=3

Scale a service to 3 replicas

docker login

Log in to Docker Hub (or other registry)

docker login ghcr.io

Log in to GitHub Container Registry

docker logout

Log out from a Docker registry

docker search <term>

Search Docker Hub for images

docker pull ghcr.io/owner/image:tag

Pull from GitHub Container Registry

docker tag app:latest registry.io/app:v1

Tag image for a private registry

docker push registry.io/app:v1

Push image to a private registry

docker inspect <container>

Display detailed container information as JSON

docker inspect --format '{{.State.Status}}' <container>

Get specific field from inspect output

docker logs <container>

Show container logs

docker logs -f --tail 100 <container>

Follow last 100 lines of container logs

docker logs --since 1h <container>

Show logs from the last hour

docker top <container>

Display running processes in a container

docker stats

Live stream of container resource usage

docker stats --no-stream

Show resource usage snapshot (no live update)

docker events

Stream real-time events from the Docker daemon

docker diff <container>

Show filesystem changes in a container

docker system df

Show Docker disk usage summary

docker system df -v

Show detailed disk usage per item

docker system prune

Remove unused containers, networks, and dangling images

docker system prune -a --volumes

Remove ALL unused data including volumes

docker image prune

Remove dangling (untagged) images

docker image prune -a

Remove all unused images

docker container prune

Remove all stopped containers

docker volume prune

Remove all unused volumes

docker builder prune

Remove build cache

docker info

Display system-wide Docker information

docker version

Show Docker client and server version

docker build -t app:latest .

Build image from Dockerfile in current directory

docker build -t app:v1 -f Dockerfile.prod .

Build using a specific Dockerfile

docker build --no-cache -t app:latest .

Build without using layer cache

docker build --build-arg VERSION=1.0 .

Build with a build-time variable

docker build --target builder .

Build up to a specific multi-stage target

docker buildx build --platform linux/amd64,linux/arm64 -t app .

Build multi-platform image

docker buildx create --use

Create and switch to a new buildx builder

docker buildx ls

List available buildx builders

docker exec -it <container> bash

Open interactive bash shell in a running container

docker exec -it <container> sh

Open shell (for Alpine/minimal images)

docker exec <container> ls /app

Run a single command in a container

docker exec -u root <container> apt update

Run command as root user

docker exec -e VAR=value <container> env

Run with an additional environment variable

docker attach <container>

Attach terminal to a running container's main process

docker cp <container>:/path/file .

Copy file from container to host

docker cp file.txt <container>:/path/

Copy file from host to container

docker export <container> > backup.tar

Export container filesystem as tar archive

docker commit <container> image:tag

Create a new image from a container's changes

Commands shown are for Docker Engine 20+ and Docker Compose v2.

Ad 320×100

Docker Cheat Sheet

A free, searchable Docker cheat sheet with the most useful commands, flags, and shortcuts in one place. Quickly look up syntax, copy commands, and learn Docker containers faster — perfect for beginners and a handy reference for experienced users.

FAQ

Is this Docker cheat sheet free?
Yes. The entire cheat sheet is free to browse and copy from, with no sign-up required.
Can I search for a specific command?
Yes. Use the search to filter the Docker commands instantly and jump straight to the syntax you need.
Who is the Docker cheat sheet for?
It suits everyone from newcomers learning Docker containers to power users who want a quick reminder of less-used flags and shortcuts.