Skip to main content

Docker Compose Reference

v1.0.0

Service, network, volume, and deploy fields for Docker Compose file authoring.

18 entries found

services
objectTop-level
services

Defines the set of containers in the application. Each key is a service name.

services:
  web:
    image: nginx:alpine
  db:
    image: postgres:16
volumes
objectTop-level
volumes

Declares named volumes shared between services. Can be backed by a driver or marked external.

volumes:
  pgdata:
  uploads:
    driver: local
networks
objectTop-level
networks

Declares named networks. Services are connected to their listed networks. Default driver is bridge.

networks:
  frontend:
  backend:
    internal: true
image
stringService
services.<name>.image

Specifies the image to start the container from. Cannot be used with build at the same time.

services:
  web:
    image: nginx:1.25-alpine
build
string | objectService
services.<name>.build

Configures build-time options. Short form is a path to the Dockerfile context. Long form supports context, dockerfile, args, target.

services:
  api:
    build:
      context: ./api
      dockerfile: Dockerfile.prod
      args:
        VERSION: "1.2.3"
ports
listService
services.<name>.ports

Maps container ports to the host. Short syntax: HOST:CONTAINER. Can also specify protocol (tcp/udp).

services:
  web:
    ports:
      - "80:80"
      - "443:443"
      - "127.0.0.1:5432:5432"
environment
list | objectService
services.<name>.environment

Sets environment variables in the container. Map or list syntax. Use env_file to load from files.

services:
  api:
    environment:
      NODE_ENV: production
      PORT: 3000
      DATABASE_URL: postgres://db/app
env_file
string | listService
services.<name>.env_file

Loads environment variables from one or more .env files. Variables are not accessible during the build step.

services:
  api:
    env_file:
      - .env
      - .env.local
volumes
listService
services.<name>.volumes

Mounts host paths or named volumes into the container. Short syntax: SOURCE:TARGET[:MODE].

services:
  db:
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
depends_on
list | objectService
services.<name>.depends_on

Express startup dependencies between services. Long form supports condition: service_healthy to wait for healthchecks.

services:
  api:
    depends_on:
      db:
        condition: service_healthy
networks
list | objectService
services.<name>.networks

Connects the service to named networks. If omitted, the service joins the default network.

services:
  api:
    networks:
      - frontend
      - backend
restart
stringService
services.<name>.restart

Restart policy: no (default), always, on-failure, unless-stopped.

services:
  worker:
    restart: unless-stopped
healthcheck
objectService
services.<name>.healthcheck

Configures a health test for the container. test is a command list; interval, timeout, retries control the behaviour.

services:
  db:
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
command
string | listService
services.<name>.command

Overrides the default CMD from the image. String or list form.

services:
  worker:
    command: python manage.py rqworker default
profiles
listService
services.<name>.profiles

Assigns profiles to a service. Services with profiles are only started when the profile is active (--profile flag or COMPOSE_PROFILES env var).

services:
  debug-tools:
    image: nicolaka/netshoot
    profiles: [debug]
deploy.replicas
integerDeploy
services.<name>.deploy.replicas

Number of container replicas (Swarm only). Ignored by docker compose without --compatibility flag.

services:
  web:
    deploy:
      replicas: 3
      update_config:
        parallelism: 1
external
booleanVolume
volumes.<name>.external

Marks a volume as externally managed. Compose will not create or remove it; it must exist before the stack is started.

volumes:
  secrets:
    external: true
internal
booleanNetwork
networks.<name>.internal

Restricts external access to the network. Containers on an internal network can only communicate with each other.

networks:
  backend:
    internal: true