Skip to content

Instantly share code, notes, and snippets.

@paulknulst
Last active December 16, 2023 06:11
Show Gist options
  • Save paulknulst/68e5e63badaa6a9ac80b4227ca07baee to your computer and use it in GitHub Desktop.
Save paulknulst/68e5e63badaa6a9ac80b4227ca07baee to your computer and use it in GitHub Desktop.
my first docker-compose for a traefik service
version: "3.3"
services:
traefik:
image: "traefik:v2.2.1"
container_name: traefik
hostname: traefik
command:
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --providers.docker
- --providers.docker.exposedByDefault=false
- --api
- --certificatesresolvers.le.acme.email=${TRAEFIK_SSLEMAIL?Variable not set}
- --certificatesresolvers.le.acme.storage=./acme.json
- --certificatesresolvers.le.acme.tlschallenge=true
ports:
- "80:80"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./acme.json:/acme.json"
labels:
- "traefik.enable=true"
# Dashboard
- "traefik.http.routers.traefik.rule=Host(`dashboard.${PRIMARY_DOMAIN}`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.tls=true"
- "traefik.http.routers.traefik.tls.certresolver=le"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.routers.traefik.middlewares=authtraefik"
- "traefik.http.middlewares.authtraefik.basicauth.users=devAdmin:$$2y$$05$$h9OxLeY20/5uiXjfPgdRxuFlrfqBf2QifYDgrwsR6rAEgX3/dpOGq" # user:devAdmin, password:devto
# global redirect to https
- "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
- "traefik.http.routers.http-catchall.entrypoints=web"
- "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
# middleware redirect
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
restart: unless-stopped
networks:
- traefik-public
my-app:
image: containous/whoami:v1.3.0
hostname: whoami
container_name: whoami
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.my-app.rule=Host(`whoami.${PRIMARY_DOMAIN}`)"
- "traefik.http.routers.my-app.middlewares=auth"
- "traefik.http.routers.my-app.entrypoints=websecure"
- "traefik.http.routers.my-app.tls=true"
- "traefik.http.routers.my-app.tls.certresolver=le"
- "traefik.http.middlewares.authtraefik.basicauth.users=devAdmin:$$2y$$05$$h9OxLeY20/5uiXjfPgdRxuFlrfqBf2QifYDgrwsR6rAEgX3/dpOGq" # user:devAdmin, password:devto
networks:
- traefik-public
networks:
traefik-public:
external: true
@paulknulst
Copy link
Author

Thank you for pointing this out. I will adjust the Compose file and test it later.

@benbelo
Copy link

benbelo commented Aug 23, 2023

Bit late but... line 55 there is a : on the network traefik-public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment