DevOps Tools
Docker Compose Reference
Searchable, categorized Docker Compose directives with YAML examples. No sign-up required.
image
ServicesSpecify the image to start the container from. Can be a repository/tag or partial image ID.
Example:
image: nginx:alpineValid Values:
Any valid Docker image reference (e.g. ubuntu:22.04, myregistry.io/app:latest)
build
ServicesConfiguration options applied at build time. Can be a path string or a detailed object with context, dockerfile, args, and more.
Example:
build:
context: ./app
dockerfile: Dockerfile.prod
args:
NODE_ENV: productionValid Values:
String path or object with context, dockerfile, args, target, cache_from, labels, shm_size
container_name
ServicesSpecify a custom container name, rather than a generated default name.
Example:
container_name: my-web-appValid Values:
Any valid container name string
command
ServicesOverride the default command declared by the container image.
Example:
command: ["python", "app.py", "--debug"]Valid Values:
String or list of strings
entrypoint
ServicesOverride the default entrypoint declared by the container image.
Example:
entrypoint: /app/start.shValid Values:
String or list of strings
environment
ServicesAdd environment variables. Can use an array or a dictionary.
Example:
environment:
NODE_ENV: production
DB_HOST: postgres
DEBUG: "false"Valid Values:
Map of KEY: VALUE pairs or list of KEY=VALUE strings
env_file
ServicesAdd environment variables from a file. Each line should be in VAR=VAL format.
Example:
env_file:
- .env
- .env.productionValid Values:
String path or list of paths to .env files
ports
ServicesExpose ports. Specify both host and container ports (HOST:CONTAINER), or just the container port.
Example:
ports:
- "3000:3000"
- "8080:80"
- "443:443/tcp"Valid Values:
List of port mappings in SHORT or LONG syntax, optional /tcp or /udp protocol
expose
ServicesExpose ports without publishing them to the host. Only accessible to linked services.
Example:
expose:
- "3000"
- "8080"Valid Values:
List of port numbers as strings
volumes
ServicesMount host paths or named volumes. Specified as a list of volume mappings.
Example:
volumes:
- ./data:/app/data
- db-data:/var/lib/postgresql/data
- /tmp/cache:/tmp/cache:roValid Values:
SHORT syntax HOST:CONTAINER[:MODE] or LONG syntax with type, source, target, read_only
networks
ServicesNetworks to join. References top-level networks entries.
Example:
networks:
- frontend
- backendValid Values:
List of network names or map with aliases, ipv4_address, ipv6_address, priority
depends_on
ServicesExpress dependency between services. Controls startup and shutdown order.
Example:
depends_on:
db:
condition: service_healthy
redis:
condition: service_startedValid Values:
List of service names or map with condition (service_started, service_healthy, service_completed_successfully)
restart
ServicesRestart policy to apply when a container exits.
Example:
restart: unless-stoppedValid Values:
"no" | always | on-failure | on-failure:N | unless-stopped
healthcheck
ServicesConfigure a check that runs to determine whether the container is healthy.
Example:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40sValid Values:
Object with test, interval, timeout, retries, start_period, start_interval, disable
deploy
ServicesSpecify configuration related to deployment and running of services (Swarm mode and resource limits).
Example:
deploy:
replicas: 3
resources:
limits:
cpus: "0.5"
memory: 512M
reservations:
cpus: "0.25"
memory: 256MValid Values:
Object with replicas, resources, restart_policy, placement, update_config, rollback_config, labels
labels
ServicesAdd metadata to containers using Docker labels.
Example:
labels:
com.example.project: "myapp"
traefik.enable: "true"Valid Values:
Map of key-value string pairs or list of key=value strings
logging
ServicesLogging configuration for the service.
Example:
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"Valid Values:
Object with driver (json-file, syslog, none, etc.) and driver-specific options map
working_dir
ServicesOverride the containers working directory from that specified by the image.
Example:
working_dir: /appValid Values:
Absolute path inside the container
user
ServicesOverride the default user within the container.
Example:
user: "1000:1000"Valid Values:
Username, UID, UID:GID, or user:group
stdin_open
ServicesKeep STDIN open even if not attached. Equivalent to docker run -i.
Example:
stdin_open: trueValid Values:
true | false
tty
ServicesAllocate a pseudo-TTY. Equivalent to docker run -t.
Example:
tty: trueValid Values:
true | false
privileged
ServicesGive extended privileges to this container. Grants access to all devices.
Example:
privileged: trueValid Values:
true | false
cap_add
ServicesAdd container Linux capabilities.
Example:
cap_add:
- SYS_PTRACE
- NET_ADMINValid Values:
List of Linux capabilities (SYS_PTRACE, NET_ADMIN, SYS_TIME, etc.)
cap_drop
ServicesDrop container Linux capabilities.
Example:
cap_drop:
- ALLValid Values:
List of Linux capabilities or ALL
tmpfs
ServicesMount a temporary filesystem inside the container. Can be a single value or a list.
Example:
tmpfs:
- /tmp
- /runValid Values:
String path or list of paths, optional size and mode options
secrets
ServicesGrant access to secrets on a per-service basis using per-service secrets configuration.
Example:
secrets:
- db_password
- source: api_key
target: /run/secrets/api_keyValid Values:
List of secret names or objects with source, target, uid, gid, mode
configs
ServicesGrant access to configs on a per-service basis.
Example:
configs:
- my_config
- source: app_config
target: /app/config.jsonValid Values:
List of config names or objects with source, target, uid, gid, mode
ulimits
ServicesOverride the default ulimits for a container.
Example:
ulimits:
nofile:
soft: 65536
hard: 65536
nproc: 65535Valid Values:
Map of limit names to integer or object with soft/hard values
sysctls
ServicesSet kernel parameters in the container.
Example:
sysctls:
net.core.somaxconn: 1024
net.ipv4.tcp_syncookies: 0Valid Values:
Map of kernel parameter names to values or list of key=value
extra_hosts
ServicesAdd hostname mappings. Same as docker run --add-host.
Example:
extra_hosts:
- "somehost:162.242.195.82"
- "host.docker.internal:host-gateway"Valid Values:
List of HOSTNAME:IP mappings
dns
ServicesCustom DNS servers to set on the container.
Example:
dns:
- 8.8.8.8
- 8.8.4.4Valid Values:
Single IP or list of DNS server IPs
dns_search
ServicesCustom DNS search domains to set on the container.
Example:
dns_search:
- example.com
- dc1.example.comValid Values:
Single domain or list of search domains
hostname
ServicesSet the containers hostname.
Example:
hostname: my-serviceValid Values:
Any valid hostname string
domainname
ServicesSet the containers domain name.
Example:
domainname: example.comValid Values:
Any valid domain name string
links
ServicesLink to containers in another service. Deprecated in favor of networks.
Example:
links:
- db
- cache:redisValid Values:
List of SERVICE or SERVICE:ALIAS
external_links
ServicesLink to containers outside this docker-compose.yml or even outside the project.
Example:
external_links:
- redis_1
- project_db_1:mysqlValid Values:
List of CONTAINER or CONTAINER:ALIAS
pid
ServicesSet PID mode to the host PID mode, sharing the process ID address space with the host.
Example:
pid: hostValid Values:
"host" or "service:<service_name>"
ipc
ServicesConfigure IPC isolation mode.
Example:
ipc: hostValid Values:
"host" | "private" | "shareable" | "service:<service_name>"
stop_signal
ServicesSet an alternative signal to stop the container. Default is SIGTERM.
Example:
stop_signal: SIGQUITValid Values:
Any valid signal name (SIGTERM, SIGINT, SIGQUIT, SIGKILL, etc.)
stop_grace_period
ServicesHow long to wait when stopping a container before sending SIGKILL.
Example:
stop_grace_period: 30sValid Values:
Duration string (e.g. 10s, 1m30s, 2m)
security_opt
ServicesOverride the default labeling scheme for each container.
Example:
security_opt:
- no-new-privileges:true
- seccomp:unconfinedValid Values:
List of security options
shm_size
ServicesSize of /dev/shm (shared memory). Default is 64M.
Example:
shm_size: 256MValid Values:
Byte value as integer or string with unit (e.g. 256M, 1G)
platform
ServicesDefine the target platform for the container image.
Example:
platform: linux/amd64Valid Values:
os/arch string (linux/amd64, linux/arm64, linux/arm/v7, etc.)
profiles
ServicesDefine a list of named profiles for the service to be enabled under.
Example:
profiles:
- debug
- developmentValid Values:
List of profile name strings
pull_policy
ServicesDefine the decisions Compose makes when it starts to pull images.
Example:
pull_policy: alwaysValid Values:
always | never | missing | build
read_only
ServicesMount the containers root filesystem as read only.
Example:
read_only: trueValid Values:
true | false
init
ServicesRun an init process (PID 1) inside the container that forwards signals and reaps processes.
Example:
init: trueValid Values:
true | false
scale
ServicesSpecify the default number of containers to deploy for this service.
Example:
scale: 3Valid Values:
Positive integer
driver
NetworksSpecify which driver should be used for this network.
Example:
networks:
frontend:
driver: bridgeValid Values:
bridge | overlay | host | none | macvlan | ipvlan | custom plugin
driver_opts
NetworksSpecify driver-specific options as key-value pairs.
Example:
networks:
backend:
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "127.0.0.1"Valid Values:
Map of driver-specific option keys to string values
ipam
NetworksSpecify custom IPAM (IP Address Management) configuration.
Example:
networks:
app-net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
gateway: 172.28.0.1Valid Values:
Object with driver, config (list of subnet, ip_range, gateway, aux_addresses)
external (network)
NetworksIf set to true, specifies that the network has been created outside of Compose and Compose will not attempt to create it.
Example:
networks:
existing-net:
external: trueValid Values:
true | false, or object with name
internal
NetworksRestrict external access to the network. Containers can communicate with each other but not the outside world.
Example:
networks:
isolated:
internal: trueValid Values:
true | false
attachable
NetworksIf true, standalone containers can attach to this network in addition to services.
Example:
networks:
shared:
attachable: trueValid Values:
true | false
enable_ipv6
NetworksEnable IPv6 networking on this network.
Example:
networks:
ip6net:
enable_ipv6: trueValid Values:
true | false
labels (network)
NetworksAdd metadata to the network using Docker labels.
Example:
networks:
frontend:
labels:
com.example.project: "myapp"Valid Values:
Map of key-value pairs or list of key=value strings
name (network)
NetworksSet a custom name for this network. Can be used with external.
Example:
networks:
my-net:
name: my-custom-networkValid Values:
Any valid network name string
driver (volume)
VolumesSpecify which volume driver should be used for this volume.
Example:
volumes:
data:
driver: localValid Values:
local | nfs | cifs | custom plugin drivers
driver_opts (volume)
VolumesSpecify driver-specific options for the volume as key-value pairs.
Example:
volumes:
nfs-data:
driver_opts:
type: nfs
o: "addr=10.0.0.1,rw"
device: ":/exported/path"Valid Values:
Map of driver-specific option keys to string values
external (volume)
VolumesIf true, specifies that this volume already exists on the platform and Compose does not attempt to create it.
Example:
volumes:
db-data:
external: trueValid Values:
true | false, or object with name
labels (volume)
VolumesAdd metadata to the volume using Docker labels.
Example:
volumes:
data:
labels:
com.example.backup: "daily"Valid Values:
Map of key-value pairs or list of key=value strings
name (volume)
VolumesSet a custom name for this volume.
Example:
volumes:
data:
name: my-app-dataValid Values:
Any valid volume name string
file (config)
ConfigsThe config is created with the contents of the file at the specified path.
Example:
configs:
app_config:
file: ./config/app.jsonValid Values:
Relative or absolute path to the config file
environment (config)
ConfigsThe config content is set from the value of an environment variable.
Example:
configs:
token:
environment: API_TOKENValid Values:
Environment variable name string
content (config)
ConfigsThe config content is set with the inlined value.
Example:
configs:
http_config:
content: |
max_connections=100
timeout=30Valid Values:
Inline string content, supports multi-line with | or >
external (config)
ConfigsIf true, the config has already been created in Docker and Compose does not attempt to create it.
Example:
configs:
app_config:
external: trueValid Values:
true | false
name (config)
ConfigsThe name of the config object in Docker. Allows referencing configs with different Compose and Docker names.
Example:
configs:
app_config:
name: my-app-config-v2Valid Values:
Any valid config name string
template_driver
ConfigsThe name of the templating driver to use for rendering the config data.
Example:
configs:
app_config:
template_driver: golangValid Values:
golang | any supported template engine