Skip to main content

DevOps Tools

Docker Compose Reference

Searchable, categorized Docker Compose directives with YAML examples. No sign-up required.

Filter by:
Showing 68 of 68 directives

image

Services

Specify the image to start the container from. Can be a repository/tag or partial image ID.

Example:

image: nginx:alpine

Valid Values:

Any valid Docker image reference (e.g. ubuntu:22.04, myregistry.io/app:latest)

build

Services

Configuration 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: production

Valid Values:

String path or object with context, dockerfile, args, target, cache_from, labels, shm_size

container_name

Services

Specify a custom container name, rather than a generated default name.

Example:

container_name: my-web-app

Valid Values:

Any valid container name string

command

Services

Override the default command declared by the container image.

Example:

command: ["python", "app.py", "--debug"]

Valid Values:

String or list of strings

entrypoint

Services

Override the default entrypoint declared by the container image.

Example:

entrypoint: /app/start.sh

Valid Values:

String or list of strings

environment

Services

Add 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

Services

Add environment variables from a file. Each line should be in VAR=VAL format.

Example:

env_file:
  - .env
  - .env.production

Valid Values:

String path or list of paths to .env files

ports

Services

Expose 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

Services

Expose 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

Services

Mount 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:ro

Valid Values:

SHORT syntax HOST:CONTAINER[:MODE] or LONG syntax with type, source, target, read_only

networks

Services

Networks to join. References top-level networks entries.

Example:

networks:
  - frontend
  - backend

Valid Values:

List of network names or map with aliases, ipv4_address, ipv6_address, priority

depends_on

Services

Express dependency between services. Controls startup and shutdown order.

Example:

depends_on:
  db:
    condition: service_healthy
  redis:
    condition: service_started

Valid Values:

List of service names or map with condition (service_started, service_healthy, service_completed_successfully)

restart

Services

Restart policy to apply when a container exits.

Example:

restart: unless-stopped

Valid Values:

"no" | always | on-failure | on-failure:N | unless-stopped

healthcheck

Services

Configure 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: 40s

Valid Values:

Object with test, interval, timeout, retries, start_period, start_interval, disable

deploy

Services

Specify 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: 256M

Valid Values:

Object with replicas, resources, restart_policy, placement, update_config, rollback_config, labels

labels

Services

Add 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

Services

Logging 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

Services

Override the containers working directory from that specified by the image.

Example:

working_dir: /app

Valid Values:

Absolute path inside the container

user

Services

Override the default user within the container.

Example:

user: "1000:1000"

Valid Values:

Username, UID, UID:GID, or user:group

stdin_open

Services

Keep STDIN open even if not attached. Equivalent to docker run -i.

Example:

stdin_open: true

Valid Values:

true | false

tty

Services

Allocate a pseudo-TTY. Equivalent to docker run -t.

Example:

tty: true

Valid Values:

true | false

privileged

Services

Give extended privileges to this container. Grants access to all devices.

Example:

privileged: true

Valid Values:

true | false

cap_add

Services

Add container Linux capabilities.

Example:

cap_add:
  - SYS_PTRACE
  - NET_ADMIN

Valid Values:

List of Linux capabilities (SYS_PTRACE, NET_ADMIN, SYS_TIME, etc.)

cap_drop

Services

Drop container Linux capabilities.

Example:

cap_drop:
  - ALL

Valid Values:

List of Linux capabilities or ALL

tmpfs

Services

Mount a temporary filesystem inside the container. Can be a single value or a list.

Example:

tmpfs:
  - /tmp
  - /run

Valid Values:

String path or list of paths, optional size and mode options

secrets

Services

Grant access to secrets on a per-service basis using per-service secrets configuration.

Example:

secrets:
  - db_password
  - source: api_key
    target: /run/secrets/api_key

Valid Values:

List of secret names or objects with source, target, uid, gid, mode

configs

Services

Grant access to configs on a per-service basis.

Example:

configs:
  - my_config
  - source: app_config
    target: /app/config.json

Valid Values:

List of config names or objects with source, target, uid, gid, mode

ulimits

Services

Override the default ulimits for a container.

Example:

ulimits:
  nofile:
    soft: 65536
    hard: 65536
  nproc: 65535

Valid Values:

Map of limit names to integer or object with soft/hard values

sysctls

Services

Set kernel parameters in the container.

Example:

sysctls:
  net.core.somaxconn: 1024
  net.ipv4.tcp_syncookies: 0

Valid Values:

Map of kernel parameter names to values or list of key=value

extra_hosts

Services

Add 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

Services

Custom DNS servers to set on the container.

Example:

dns:
  - 8.8.8.8
  - 8.8.4.4

Valid Values:

Single IP or list of DNS server IPs

dns_search

Services

Custom DNS search domains to set on the container.

Example:

dns_search:
  - example.com
  - dc1.example.com

Valid Values:

Single domain or list of search domains

hostname

Services

Set the containers hostname.

Example:

hostname: my-service

Valid Values:

Any valid hostname string

domainname

Services

Set the containers domain name.

Example:

domainname: example.com

Valid Values:

Any valid domain name string

links

Services

Link to containers in another service. Deprecated in favor of networks.

Example:

links:
  - db
  - cache:redis

Valid Values:

List of SERVICE or SERVICE:ALIAS

external_links

Services

Link to containers outside this docker-compose.yml or even outside the project.

Example:

external_links:
  - redis_1
  - project_db_1:mysql

Valid Values:

List of CONTAINER or CONTAINER:ALIAS

pid

Services

Set PID mode to the host PID mode, sharing the process ID address space with the host.

Example:

pid: host

Valid Values:

"host" or "service:<service_name>"

ipc

Services

Configure IPC isolation mode.

Example:

ipc: host

Valid Values:

"host" | "private" | "shareable" | "service:<service_name>"

stop_signal

Services

Set an alternative signal to stop the container. Default is SIGTERM.

Example:

stop_signal: SIGQUIT

Valid Values:

Any valid signal name (SIGTERM, SIGINT, SIGQUIT, SIGKILL, etc.)

stop_grace_period

Services

How long to wait when stopping a container before sending SIGKILL.

Example:

stop_grace_period: 30s

Valid Values:

Duration string (e.g. 10s, 1m30s, 2m)

security_opt

Services

Override the default labeling scheme for each container.

Example:

security_opt:
  - no-new-privileges:true
  - seccomp:unconfined

Valid Values:

List of security options

shm_size

Services

Size of /dev/shm (shared memory). Default is 64M.

Example:

shm_size: 256M

Valid Values:

Byte value as integer or string with unit (e.g. 256M, 1G)

platform

Services

Define the target platform for the container image.

Example:

platform: linux/amd64

Valid Values:

os/arch string (linux/amd64, linux/arm64, linux/arm/v7, etc.)

profiles

Services

Define a list of named profiles for the service to be enabled under.

Example:

profiles:
  - debug
  - development

Valid Values:

List of profile name strings

pull_policy

Services

Define the decisions Compose makes when it starts to pull images.

Example:

pull_policy: always

Valid Values:

always | never | missing | build

read_only

Services

Mount the containers root filesystem as read only.

Example:

read_only: true

Valid Values:

true | false

init

Services

Run an init process (PID 1) inside the container that forwards signals and reaps processes.

Example:

init: true

Valid Values:

true | false

scale

Services

Specify the default number of containers to deploy for this service.

Example:

scale: 3

Valid Values:

Positive integer

driver

Networks

Specify which driver should be used for this network.

Example:

networks:
  frontend:
    driver: bridge

Valid Values:

bridge | overlay | host | none | macvlan | ipvlan | custom plugin

driver_opts

Networks

Specify 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

Networks

Specify custom IPAM (IP Address Management) configuration.

Example:

networks:
  app-net:
    ipam:
      driver: default
      config:
        - subnet: 172.28.0.0/16
          gateway: 172.28.0.1

Valid Values:

Object with driver, config (list of subnet, ip_range, gateway, aux_addresses)

external (network)

Networks

If 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: true

Valid Values:

true | false, or object with name

internal

Networks

Restrict external access to the network. Containers can communicate with each other but not the outside world.

Example:

networks:
  isolated:
    internal: true

Valid Values:

true | false

attachable

Networks

If true, standalone containers can attach to this network in addition to services.

Example:

networks:
  shared:
    attachable: true

Valid Values:

true | false

enable_ipv6

Networks

Enable IPv6 networking on this network.

Example:

networks:
  ip6net:
    enable_ipv6: true

Valid Values:

true | false

labels (network)

Networks

Add 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)

Networks

Set a custom name for this network. Can be used with external.

Example:

networks:
  my-net:
    name: my-custom-network

Valid Values:

Any valid network name string

driver (volume)

Volumes

Specify which volume driver should be used for this volume.

Example:

volumes:
  data:
    driver: local

Valid Values:

local | nfs | cifs | custom plugin drivers

driver_opts (volume)

Volumes

Specify 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)

Volumes

If true, specifies that this volume already exists on the platform and Compose does not attempt to create it.

Example:

volumes:
  db-data:
    external: true

Valid Values:

true | false, or object with name

labels (volume)

Volumes

Add 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)

Volumes

Set a custom name for this volume.

Example:

volumes:
  data:
    name: my-app-data

Valid Values:

Any valid volume name string

file (config)

Configs

The config is created with the contents of the file at the specified path.

Example:

configs:
  app_config:
    file: ./config/app.json

Valid Values:

Relative or absolute path to the config file

environment (config)

Configs

The config content is set from the value of an environment variable.

Example:

configs:
  token:
    environment: API_TOKEN

Valid Values:

Environment variable name string

content (config)

Configs

The config content is set with the inlined value.

Example:

configs:
  http_config:
    content: |
      max_connections=100
      timeout=30

Valid Values:

Inline string content, supports multi-line with | or >

external (config)

Configs

If true, the config has already been created in Docker and Compose does not attempt to create it.

Example:

configs:
  app_config:
    external: true

Valid Values:

true | false

name (config)

Configs

The name of the config object in Docker. Allows referencing configs with different Compose and Docker names.

Example:

configs:
  app_config:
    name: my-app-config-v2

Valid Values:

Any valid config name string

template_driver

Configs

The name of the templating driver to use for rendering the config data.

Example:

configs:
  app_config:
    template_driver: golang

Valid Values:

golang | any supported template engine