Tool cheatsheet
Docker Compose file Cheatsheet
compose.yaml snippets for services, ports, volumes, networks, environment, health checks, profiles and development workflows.
Services
- A web app with a database — Two services: an app built from a Dockerfile, and PostgreSQL with a named volume. Keep real passwords in an env file.
- Use an image or build one — Pull an image, or build from a folder with build arguments.
- Publish ports — Map host ports to container ports. Bind to localhost to keep a port private to your machine.
- Override the command — Change the command or entrypoint that the image defines.
- Restart automatically — Restart on failure, or unless you stop it manually.
- Add a health check — Mark a service healthy only when a command succeeds.
- Wait for a dependency to be healthy — Start a service only after another reports healthy.
- Limit CPU and memory — Cap what a service can use.
Environment and secrets
- Set environment variables — Set variables inline, as a list or a map.
- Load variables from a file — Read variables from one or more env files. Keep them out of version control.
- Use variables with defaults — Substitute values from the shell or .env, with a default or a required error.
- Use secrets — Mount a secret as a file under /run/secrets rather than an environment variable.
- Mount a config file — Provide a configuration file to a service.
Volumes and networks
- Use a named volume — Persist data in a volume managed by Docker.
- Mount a host folder — Mount source code into a container for development. :ro makes it read-only.
- Use an in-memory mount — Mount temporary storage in memory.
- Create separate networks — Isolate services: the proxy can reach the app, but not the database.
- Join an existing network — Attach to a network created outside this file.
Profiles, development and reuse
- Make services optional — Start a service only when its profile is enabled, with docker compose --profile debug up.
- Sync or rebuild on file changes — Update running containers as you edit code, with docker compose watch.
- Override settings for development — compose.override.yaml is merged automatically over compose.yaml.
- Include another Compose file — Reuse a service definition kept in a separate file.
- Avoid repetition with anchors — Define settings once and reuse them in several services.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.