Before you use this reference
This page is a lookup, not a tutorial. The explanations are in Why Containers, Writing a Dockerfile, Docker Compose Basics, and Building the Data Stack.
Core vocabulary#
| Term | Meaning |
|---|---|
| Image | Immutable package: file system + default command |
| Container | A running instance of an image |
| Registry | Where images are stored and pulled (Docker Hub) |
| Volume | Storage that outlives a container |
| Bind mount | A host path mounted into a container |
| Compose project | A set of services managed together from one file |
docker commands#
docker run --rm -p 8123:8123 clickhouse/clickhouse-server:latestdocker ps # running containersdocker ps -a # including stopped onesdocker logs -f <name> # follow a container's outputdocker exec -it <name> bash # shell inside a running containerdocker stop <name> # stop itdocker rm <name> # remove a stopped containerdocker images # local imagesdocker rmi <image> # remove an imagedocker build -t name:tag . # build an image from the current directorydocker system prune # remove stopped containers, unused networks/imagesdocker run flags:
| Flag | Effect |
|---|---|
--rm | Delete the container when it stops |
-p H:C | Publish container port C on host port H |
-e KEY=value | Set an environment variable |
-v name:/path | Mount a named volume |
-v ./path:/path | Bind-mount a host directory |
-d | Run detached (in the background) |
--name | Give the container a fixed name |
docker compose commands#
docker compose up -d # start all services in the backgrounddocker compose up -d --build # rebuild images firstdocker compose ps # status of each servicedocker compose logs -f <service> # follow one service's logsdocker compose exec <service> sh # shell inside a servicedocker compose build # build images for services with `build:`docker compose stop # stop containers, keep themdocker compose start # start stopped containersdocker compose restart <service> # restart one servicedocker compose down # stop and remove containers + networkdocker compose down -v # also delete named volumes (wipes data)docker compose config # print the resolved, merged configDockerfile instructions#
FROM image:tag # base image; always pin the tagUSER name # user for later instructions and the containerRUN command # run at build time; each RUN is a cached layerCOPY src dst # copy from the build context into the imageENV KEY=value # environment variable baked into the imageWORKDIR /path # working directory for later instructionsEXPOSE 8080 # documents a port (does not publish it)CMD ["executable", "arg"] # default command when the container startsENTRYPOINT ["executable"] # fixed command; CMD becomes its argumentsLayer-cache rule: order instructions least-changed first. Install system and
Python packages before COPY-ing source.
Compose file keys#
services: name: image: repo/name:tag # OR build: . # build from ./Dockerfile container_name: name # fixed name instead of the generated one command: ["..."] # override the image's default command ports: - "HOST:CONTAINER" environment: - KEY=value # list form KEY: value # OR map form volumes: - named_volume:/in/container - ./host/path:/in/container depends_on: other: condition: service_healthy healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"] interval: 10s timeout: 5s retries: 5 start_period: 30s restart: always # always | unless-stopped | "no"
volumes: named_volume: # declare every named volume hereNetworking rule#
| Talking from | Use address |
|---|---|
| Your machine | localhost:<published-host-port> |
| One container to another | <service-name>:<container-port> |
Inside a container, localhost is that container, not the host or another
service.
Volumes#
| Kind | Source | Deleted by | Use for |
|---|---|---|---|
| Named volume | a name under top-level volumes: | docker compose down -v | database data directories |
| Bind mount | a host path (./dags) | never (it is your file) | source code, config, logs |
Common failure to check first#
| Symptom | Usual cause |
|---|---|
port is already allocated | Another process (or a stale container) uses that host port |
| Service connects then hangs | Wrong host: used localhost instead of the service name from a container |
| Container exits immediately | Its command finished or failed; check docker compose logs <service> |
| Data gone after restart | Path was not on a volume, or down -v was run |
| Healthcheck never passes | Wrong test command, or start_period too short |