Skip to content

Cheatsheets & Reference

Docker Command Cheatsheet

Categorized Docker commands for images, containers, volumes and more.

native Client-side

Images

11
docker images

List all local images.

docker pull <image>

Download an image from a registry.

docker build -t <name> .

Build an image from a Dockerfile in the current directory.

docker build -t <name>:<tag> .

Build an image with a specific tag.

docker rmi <image>

Remove a local image.

docker image prune

Remove all dangling (unused) images.

docker image prune -a

Remove all images not used by any container.

docker tag <src> <dest>

Tag an image with a new name.

docker push <image>

Push an image to a registry.

docker save -o file.tar <image>

Save an image to a tar archive.

docker load -i file.tar

Load an image from a tar archive.

Containers

16
docker ps

List running containers.

docker ps -a

List all containers (including stopped).

docker run <image>

Create and start a container from an image.

docker run -d <image>

Run a container in detached (background) mode.

docker run -it <image> /bin/sh

Run a container with an interactive shell.

docker run -p 8080:80 <image>

Map host port 8080 to container port 80.

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

Mount a host directory into the container.

docker run --name <name> <image>

Run a container with a custom name.

docker run --rm <image>

Automatically remove the container when it exits.

docker run -e KEY=VALUE <image>

Set an environment variable in the container.

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 container prune

Remove all stopped containers.

Container Inspection & Interaction

8
docker logs <container>

View the logs of a container.

docker logs -f <container>

Follow (stream) container logs in real time.

docker exec -it <container> /bin/sh

Open an interactive shell in a running container.

docker exec <container> <cmd>

Run a command inside a running container.

docker inspect <container>

Show detailed JSON info about a container.

docker top <container>

Show running processes inside a container.

docker stats

Show real-time resource usage of all containers.

docker cp <src> <container>:<dest>

Copy files between host and container.

Volumes

5
docker volume ls

List all volumes.

docker volume create <name>

Create a named volume.

docker volume inspect <name>

Show details of a volume.

docker volume rm <name>

Remove a volume.

docker volume prune

Remove all unused volumes.

Networks

6
docker network ls

List all networks.

docker network create <name>

Create a new network.

docker network inspect <name>

Show details of a network.

docker network connect <net> <ctr>

Connect a container to a network.

docker network disconnect <net> <ctr>

Disconnect a container from a network.

docker network rm <name>

Remove a network.

Docker Compose

12
docker compose up

Create and start all services defined in docker-compose.yml.

docker compose up -d

Start services in detached (background) mode.

docker compose up --build

Build images before starting services.

docker compose down

Stop and remove containers, networks, and volumes.

docker compose down -v

Stop services and remove associated volumes.

docker compose ps

List containers managed by Compose.

docker compose logs

View logs from all Compose services.

docker compose logs -f <service>

Follow logs for a specific service.

docker compose exec <svc> <cmd>

Run a command in a running Compose service.

docker compose build

Build or rebuild service images.

docker compose pull

Pull latest images for all services.

docker compose restart

Restart all services.

System & Cleanup

5
docker system df

Show Docker disk usage.

docker system prune

Remove all unused containers, networks, and dangling images.

docker system prune -a --volumes

Remove everything unused (aggressive cleanup).

docker info

Show system-wide Docker info.

docker version

Show Docker client and server versions.

The Complete Docker Commands Cheatsheet

Docker is the industry-standard platform for containerization, enabling developers to package applications with all their dependencies into portable, reproducible containers. This Docker commands cheatsheet covers everything from basic image and container management to volumes, networks, Docker Compose workflows, and system cleanup. Each command includes a clear, one-line explanation so you know exactly what it does. Use the search bar to find commands instantly, and the copy button to grab them for your terminal. Whether you're building microservices, setting up CI/CD pipelines, or managing production deployments, this reference has you covered.

Frequently Asked Questions

What's the difference between docker run and docker exec?

docker run creates a new container from an image and starts it. docker exec runs a command inside an already running container. Use run to start new containers and exec to interact with existing ones (e.g., opening a shell with docker exec -it container /bin/sh).

How do I clean up Docker disk space?

Run docker system prune to remove stopped containers, unused networks, and dangling images. For a more aggressive cleanup, use docker system prune -a --volumes which also removes all unused images and volumes. Check disk usage first with docker system df.

What's the difference between docker compose up and docker compose start?

docker compose up creates containers if they don't exist and starts them. docker compose start only starts existing stopped containers. For most use cases, up -d (detached mode) is the command you want.

How do I view real-time logs of a Docker container?

Use docker logs -f <container> to stream logs in real time (like tail -f). For Docker Compose services, use docker compose logs -f <service-name>.