Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Docker Compose Presets

Sketch can be used to create extensible presets for entire compose files as well as individual services.

Example

Config:

docker:
  service_presets:
    # A base service preset with common configurations
    base_service:
      environment:
        TZ: Europe/Berlin
      networks:
        - my_network

    # A preset for a db service
    database:
      extends_presets:
        - base_service
      image: postgres

    caddy:
      extends_presets:
        - base_service
      image: lucaslorentz/caddy-docker-proxy:ci-alpine
      networks:
        - my_network
      ports:
        - 80:80
        - 443:443

  compose_presets:
    # Base preset for a compose file
    base:
      volumes:
        my_volume:
          external: true
      networks:
        my_network:
          external: true

    extended:
      extends_presets:
        - base
      services:
        # Using the service preset by ID
        db: database
        my_service:
          networks:
            - my_network
          volumes:
            - my_volume:/target
      volumes:
        my_other_volume:
          external: true

Command:

sketch docker-compose --service caddy extended

ℹ️ With the --service flag, extra service presets can be added to the output file.

Output:

services:
  caddy:
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    environment:
      TZ: Europe/Berlin
    networks:
    - my_network
    ports:
    - 443:443
    - 80:80
  db:
    image: postgres
    environment:
      TZ: Europe/Berlin
    networks:
    - my_network
  my_service:
    networks:
    - my_network
    volumes:
    - my_volume:/target
networks:
  my_network:
    external: true
volumes:
  my_other_volume:
    external: true
  my_volume:
    external: true