Traefik v2 Configuration Example

Hey,

just wanted to share my Traefik-configuration to get DATAGERRY working with Traefik-Reverseproxy v2.

version: "3.0"
services:
  nginx:
    image: nethinks/nginx:latest
    ports:
     - 8443:80
    labels:
     - "traefik.enable=true"
     - "traefik.http.routers.${servicename}.entrypoints=http"
     - "traefik.http.routers.${servicename}.rule=Host(`${Domainname}`)" # Just add your domain-name between ``
     - "traefik.http.middlewares.${servicename}-https-redirect.redirectscheme.scheme=https"
     - "traefik.http.routers.${servicename}.middlewares=${servicename}-https-redirect"
     - "traefik.http.routers.${servicename}-secure.entrypoints=https"
     - "traefik.http.routers.${servicename}-secure.rule=Host(`${Domainname}`)" # Just add your domain-name between ``
     - "traefik.http.routers.${servicename}-secure.tls=true"
     - "traefik.http.routers.${servicename}-secure.tls.certresolver=http" #This may have to change to your certificate-resolver
     - "traefik.http.routers.${servicename}-secure.service=${servicename}"
     - "traefik.http.services.${servicename}.loadbalancer.server.port=${port}"
     - "traefik.docker.network=proxy"#This may have to change to your traefik-network
     - "traefik.http.routers.${servicename}-secure.middlewares=secHeaders@file" #This file may not exist in your configuration
     
    networks:
      - proxy
      - default
      
    depends_on:
    - datagerry
    environment:
      NGINX_LOCATION_DEFAULT: "/;/;http://datagerry:4000"
    restart: unless-stopped

  datagerry:
    image: nethinks/datagerry:latest
    depends_on:
    - db
    - broker
    environment:
      DATAGERRY_Database_host: "db"
      DATAGERRY_MessageQueueing_host: "broker"
    restart: unless-stopped

  db:
    image: mongo:4.2-bionic
    restart: unless-stopped
    volumes:
      - mongodb-data:/data/db
      - mongodb-config:/data/configdb
    
  broker:
    image: rabbitmq:3.8
    restart: unless-stopped
    volumes:
      - rabbitmq-data:/var/lib/rabbitmq

volumes:
  rabbitmq-data:
  mongodb-data:
  mongodb-config:

networks: #Change this to your traefik-network
   proxy:
      external: true

Im using an .env-file for the configuration, so please change it to your variables or check my comments.

1 Like