Docker Cheat Sheet

A reference for everyday Docker, building and tagging images, running and managing containers, ports and volumes, system cleanup, and Docker Compose.

The Docker commands you need to build images and run containers. Replace IMAGE, CONTAINER, and TAG with your own values.

Images

CommandWhat it does
docker pull IMAGEDownload an image from a registry
docker imagesList local images
docker build -t name:TAG .Build an image from a Dockerfile
docker rmi IMAGERemove an image
docker tag SRC name:TAGTag an image for pushing
docker push name:TAGUpload an image to a registry

Running containers

CommandWhat it does
docker run -it IMAGE bashRun a container with an interactive shell
docker run -d -p 8080:80 IMAGERun detached, mapping host:container ports
docker run --rm IMAGERun and auto-remove when it exits
docker run -v /host:/app IMAGEMount a host folder into the container
docker run -e KEY=val IMAGESet an environment variable

Managing containers

CommandWhat it does
docker psList running containers (-a for all)
docker stop CONTAINERStop a running container
docker start CONTAINERStart a stopped container
docker rm CONTAINERRemove a stopped container
docker exec -it CONTAINER bashOpen a shell in a running container
docker logs -f CONTAINERView and follow container output

System & cleanup

CommandWhat it does
docker system dfShow disk usage by images/containers/volumes
docker system pruneRemove unused data (-a = all unused images)
docker volume lsList volumes
docker network lsList networks

Docker Compose

CommandWhat it does
docker compose up -dStart all services from compose.yaml
docker compose downStop and remove the services
docker compose psList the project's containers
docker compose logs -fFollow logs from all services
docker compose buildBuild / rebuild service images

A container is a running instance of an image. Images are layered and cached, so ordering your Dockerfile from least- to most-frequently changed (dependencies before source) makes rebuilds much faster.

What this does

A Docker cheat sheet covers building and tagging images, running and managing containers, ports and volumes, cleanup, and Docker Compose.

How to use it

  1. Browse by section.
  2. Find the command you need.
  3. Copy it with one tap.
  4. Replace image and container names.

Example

docker ps lists the containers currently running.

Sources & methodology

Last updated .

Frequently asked questions

What’s the difference between an image and a container?

An image is a read-only template; a container is a running (or stopped) instance of an image. You can start many containers from the same image.

How do I free up disk space?

Run docker system prune to remove stopped containers and unused data, or docker system prune -a to also remove all unused images. Check usage first with docker system df.

How do I get a shell inside a running container?

Use docker exec -it CONTAINER bash (or sh if bash is not installed) to open an interactive shell.