Docker Community Forums

Share and learn in the Docker community.

Shared Settings

I have a use case where I’d like to share the logging configuration among multiple services defined in a compose file.

I was wondering if there was a pattern that allowed me to do this?

Here’s an example of what I’m trying to do though it’s not working since ‘logging’ is not a valid section

logging: &logging
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"


version: "3.7"
services:
  telegraf:
    container_name: snmp-telegraf
    image: telegraf-snmp:latest
    env_file: .env
    network_mode: "host"
    restart: always
    ports:
      - 9000:9000
    depends_on:
      - vector
    volumes:
      - ./config_generate/mibs:/usr/share/snmp/mibs
      - ./telegraf/teleconf:/etc/telegraf/telegraf.d/
      - ./telegraf/gcpconf:/etc/esnet-snmp/
    <<: *logging
  config:
    container_name: snmp-config
    image: snmp-config-generate:latest
    command: "poller generate -S"
    env_file: .env
    volumes:
      - ./config_generate/config_files:/app/config_files:ro
      - ./config_generate/tmpl:/app/tmpl:ro
      - ./config_generate/mibs:/app/mibs:ro
      - ./telegraf/teleconf:/telegraf/teleconf:rw
    <<: *logging
  vector:
    image: timberio/vector:0.10.0-alpine
    env_file: .env
    volumes:
      - ./logging/:/etc/vector/
      - /var/run/docker.sock:/var/run/docker.sock
      - ./telegraf/gcpconf:/etc/vector/gcp/:ro


Is there a way to inject the same snippet to allow multiple services to use the same configuration for logging without make the settings global to the docker daemon?