✦ For everyone, free.

Practical knowledge for real and everyday life

Home

9.3 Compose Service Config

A focused guide to Compose Service Config, connecting core concepts with practical Docker and container operations.

Compose service config is the complete set of configuration options available within an individual service definition, spanning image and build settings, networking, storage, environment, resource limits, and lifecycle behavior — together fully describing how that one component of the application should run.

A Representative, Fully Configured Service

A service definition can draw on a wide range of available options simultaneously, each addressing a different aspect of that service's behavior.

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
    image: myapi:2.3.0
    ports:
      - "8080:8080"
    environment:
      - LOG_LEVEL=info
    env_file:
      - .env.api
    volumes:
      - api-data:/data
    networks:
      - app-net
    depends_on:
      - db
    restart: unless-stopped
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: "0.5"
Why Not Every Service Needs Every Option

A given service typically only needs a subset of these options, reflecting its actual requirements — a simple, off-the-shelf cache service generally needs far less configuration than a custom-built API service with specific networking, storage, and resource needs.

services:
  cache:
    image: redis:7
Organizing Configuration for Readability as Services Grow More Complex

As a service's configuration grows more extensive, organizing related options together and adding comments for anything non-obvious helps keep the definition understandable.

services:
  api:
    # Custom application image, built locally
    build: .
    # Exposed for external access via the load balancer
    ports:
      - "8080:8080"
Why Compose Service Config Matters

A thorough understanding of the full range of configuration available within a service definition is what allows Compose to fully and accurately describe each component of an application, from the simplest dependency to the most carefully configured custom service.

Content in this section