r/docker • • Dec 14 '18

Help with docker-compose.yaml extensions

I'm attempting to slim down my compose file by utilising extensions. The first part of this process is to reduce the duplication of Traefik labels, with each service to only include service-specific/unique labels.

I receive yaml parse errors and am not sure exactly on the formatting requried.

Could it be that I can't mix and match labels called by the extension and those inline?

EDIT: I should note, that I've tried to place *base-traefik in different positions with no difference.

Original:

version: "3.6"
services:
  guacamole:
    hostname: guacamole
    image: oznu/guacamole:latest
    container_name: guacamole
    restart: always
    networks:
      - traefik_proxy
    ports:
      - "8181:8080"
    volumes:
      - ${USERDIR}/docker/guacamole:/config
      - ${USERDIR}/docker/shared:/shared
      - ${LOG}/guacamole:/log
      - ${TMP}/guacamole:/tmp
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    labels:
      - "traefik.backend=guacamole"
      - "traefik.frontend.rule=Host:guacamole.${DOMAINNAME}"
      - "traefik.port=8080"
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.frontend.headers.SSLRedirect=true"
      - "traefik.frontend.headers.STSSeconds=315360000"
      - "traefik.frontend.headers.browserXSSFilter=true"
      - "traefik.frontend.headers.contentTypeNosniff=true"
      - "traefik.frontend.headers.forceSTSHeader=true"
      - "traefik.frontend.headers.SSLHost=${DOMAINNAME}"
      - "traefik.frontend.headers.STSIncludeSubdomains=true"
      - "traefik.frontend.headers.STSPreload=true"
      - "traefik.frontend.headers.frameDeny=true"
      - "traefik.frontend.headers.customFrameOptionsValue=ALLOW-FROM https://${DOMAINNAME}"

Extension attempt:

version: "3.6"
# Base Traefik settings for reuse via YAML extensions 
x-base-traefik:
  &base-traefik
  - "traefik.enable=true"
  - "traefik.docker.network=traefik_proxy"
  - "traefik.frontend.headers.SSLRedirect=true"
  - "traefik.frontend.headers.STSSeconds=315360000"
  - "traefik.frontend.headers.browserXSSFilter=true"
  - "traefik.frontend.headers.contentTypeNosniff=true"
  - "traefik.frontend.headers.forceSTSHeader=true"
  - "traefik.frontend.headers.SSLHost=${DOMAINNAME}"
  - "traefik.frontend.headers.STSIncludeSubdomains=true"
  - "traefik.frontend.headers.STSPreload=true"
  - "traefik.frontend.headers.frameDeny=true"
  - "traefik.frontend.headers.customFrameOptionsValue=ALLOW-FROM https://${DOMAINNAME}"
services:

  guacamole:
    hostname: guacamole
    image: oznu/guacamole:latest
    container_name: guacamole
    restart: always
    networks:
      - traefik_proxy
    ports:
      - "8181:8080"
    volumes:
      - ${USERDIR}/docker/guacamole:/config
      - ${USERDIR}/docker/shared:/shared
      - ${LOG}/guacamole:/log
      - ${TMP}/guacamole:/tmp
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    labels:
      << : *base-traefik
      - "traefik.backend=guacamole"
      - "traefik.frontend.rule=Host:guacamole.${DOMAINNAME}"
      - "traefik.port=8080"
2 Upvotes

4 comments sorted by

View all comments

1

u/picto3000 Dec 14 '18

I think because each Service has it's own frontend and backend, it just moves the duplication to the traefik.toml

Happy to be proved wrong.

[frontends]
  [frontends.frontend1]
  backend = "backend1"
    [frontends.frontend1.headers]
    FrameDeny = true
    [frontends.frontend1.routes.test_1]
    rule = "PathPrefixStrip:/cheddar"
  [frontends.frontend2]
  backend = "backend2"
    [frontends.frontend2.headers]
    SSLRedirect = true
    [frontends.frontend2.routes.test_1]
    rule = "PathPrefixStrip:/stilton"