Web app setup with Traefik2

  1. As a part of project.
version: "3.2"
  app:
    build:
      context: .
    environment:
      PORT: 3000
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.app.loadbalancer.server.port=3000"
      - "traefik.http.middlewares.force-sec.redirectscheme.scheme=https"
      - "traefik.http.routers.app.rule=Host(`example.dev`)"
      - "traefik.http.routers.app.entrypoints=web"
      - "traefik.http.routers.app.middlewares=force-sec"
      - "traefik.http.routers.app-sec.rule=Host(`example.dev`)"
      - "traefik.http.routers.app-sec.entrypoints=web-sec"
      - "traefik.http.routers.app-sec.tls=true"
      - "traefik.http.routers.app-sec.tls.certresolver=le"
    networks:
      - default
      - internal
  gateway:
    image: traefik
    container_name: gateway
    restart: always
    command:
      - "--providers.docker=true"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web-sec.address=:443"
      - "--providers.docker.network=app_default"
      - "--certificatesResolvers.le.acme.tlsChallenge=true"
      - "--certificatesResolvers.le.acme.email=email@example.dev"
      - "--certificatesResolvers.le.acme.storage=/acme/storage.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - acme:/acme
    networks:
      - default
      
networks:
  internal:
  
volumes:
  acme:

2. As a standalone gateway.

version: "3.2"
services:
  gateway:
    image: traefik
    restart: always
    container_name: gateway
    command:
      - "--providers.docker=true"
      - "--providers.docker.network=gateway_gateway"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websec.address=:443"
      - "--providers.docker.exposedByDefault=false"
      - "--certificatesResolvers.le.acme.tlsChallenge=true"
      - "--certificatesResolvers.le.acme.email=email@example.dev"
      - "--certificatesResolvers.le.acme.storage=/acme/storage.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - acme:/acme
    networks:
      - gateway

networks:
  gateway:
    ipam:
      driver: default

volumes:
  acme:

version: "3.2"
  app:
    build:
      context: .
    environment:
      PORT: 3000
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.app.loadbalancer.server.port=3000"
      - "traefik.http.middlewares.force-sec.redirectscheme.scheme=https"
      - "traefik.http.routers.app.rule=Host(`example.dev`)"
      - "traefik.http.routers.app.entrypoints=web"
      - "traefik.http.routers.app.middlewares=force-sec"
      - "traefik.http.routers.app-sec.rule=Host(`example.dev`)"
      - "traefik.http.routers.app-sec.entrypoints=web-sec"
      - "traefik.http.routers.app-sec.tls=true"
      - "traefik.http.routers.app-sec.tls.certresolver=le"
    networks:
      - internal
      - gateway

networks:
  internal:
  gateway:
    external:
      name: gateway_gateway