The snippet library.
Small, practical examples. Search by task or narrow things down below.
Add a fixed hostname mapping
Docker / Compose: extra_hosts adds an entry to the container’s hosts file.
Docker / Compose✓ Tested
Choose a service’s internal hostname
Docker / Compose: hostname controls the name reported inside the container.
Docker / Compose✓ Tested
Disable a service’s network interfaces
Docker / Compose: network_mode none leaves only the loopback interface.
Docker / Compose✓ Tested
Drop capabilities for a Compose service
Docker / Compose: cap_drop ALL removes optional Linux capabilities.
Docker / Compose✓ Tested
Enable an init process for a service
Docker / Compose: init adds a small PID 1 process to forward signals and reap children.
Docker / Compose✓ Tested
Give a read-only service writable scratch space
Docker / Compose: A tmpfs mount provides temporary storage independent of the root filesystem.
Docker / Compose✓ Tested
Load service variables from an env file
Docker / Compose: env_file supplies runtime environment values.
Docker / Compose✓ Tested
Mount a local input directory with long syntax
Docker / Compose: Long mount syntax makes the bind type and read-only intent explicit.
Docker / Compose✓ Tested
Override an env-file value explicitly
Docker / Compose: The environment section takes precedence over env_file.
Docker / Compose✓ Tested
Override the image entrypoint in Compose
Docker / Compose: entrypoint and command combine as executable and arguments.
Docker / Compose✓ Tested
Pass dollar expressions through Compose
Docker / Compose: Double dollar signs defer expansion to the container shell.
Docker / Compose✓ Tested
Protect a Compose service’s root filesystem
Docker / Compose: read_only rejects writes to the image filesystem.
Docker / Compose✓ Tested