🐳 Docker

← Back to Cheatsheets

A quick-reference for Docker and Docker Compose. Docker packages applications into containers — isolated, reproducible environments that run the same everywhere. Images are the blueprint; containers are running instances of an image.

Resources

Docker CLI reference Docker Compose docs Docker Hub Dockerfile guide

Images

Images are immutable snapshots built from a Dockerfile. Each RUN, COPY, and ADD instruction creates a new layer — layers are cached, so order matters for build speed.

Containers

Containers are running instances of an image. They are ephemeral by default — any filesystem changes are lost when the container is removed. Use volumes to persist data.

Volumes

Volumes persist data outside the container lifecycle. Named volumes are managed by Docker; bind mounts map a host path directly into the container.

Networks

Containers on the same network can communicate by container name. The default bridge network doesn't support DNS; create a custom network instead.

Docker Compose

Compose defines multi-container applications in a docker-compose.yml file. It handles networking, volumes, and startup order automatically.

Cleanup

Docker accumulates stopped containers, dangling images, and unused volumes over time. Use prune commands to reclaim disk space.