Skip to content

Instantly share code, notes, and snippets.

@Eragoo
Created December 21, 2022 17:29
Show Gist options
  • Save Eragoo/e4affb860a0d1fa57d3b99b6bc469f30 to your computer and use it in GitHub Desktop.
Save Eragoo/e4affb860a0d1fa57d3b99b6bc469f30 to your computer and use it in GitHub Desktop.
docker-compose for traefik with subdomains
version: '3.7'
services:
app-landing:
image: landingimage #nginx or smth
container_name: app-landing
restart: always
labels:
- traefik.http.routers.landing.rule=Host(`landing.${DOMAIN}`)
- traefik.http.routers.landing.entrypoints=https
- traefik.http.routers.landing.tls=true
- traefik.http.routers.landing.tls.certresolver=${CERT_RESOLVER}
networks:
- some-net
fornt-end:
image: #also some nginx
container_name: front-end
restart: always
labels:
- traefik.http.routers.portal.rule=Host(`devqa.${DOMAIN}`)
- traefik.http.routers.portal.entrypoints=https
- traefik.http.routers.portal.tls=true
- traefik.http.routers.portal.tls.certresolver=${CERT_RESOLVER}
depends_on:
- traefik
networks:
- some-net
mailhog:
image: registry.hub.docker.com/mailhog/mailhog
container_name: mailhog
restart: always
labels:
- traefik.http.routers.mail.rule=Host(`mail.devqa.${DOMAIN}`)
- traefik.http.routers.mail.entrypoints=https
- traefik.http.routers.mail.tls=true
- traefik.http.services.mail.loadbalancer.server.port=8025
- traefik.http.routers.mail.tls.certresolver=${CERT_RESOLVER}
depends_on:
- traefik
ports:
- 1025:1025
- 8025:8025
networks:
- some-net
traefik:
image: traefik:2.4.8
container_name: traefik
command:
# Try to enable this if something isn't working.
# Chances are, Traefik will tell you why.
# Be careful in production as it exposes the traffic you might not want to expose.
#- --log.level=DEBUG
- --entrypoints.http.address=:80
- --entrypoints.https.address=:443
- --providers.docker=true
- --api=true
# LetsEncrypt Staging Server - uncomment when testing
#- --certificatesResolvers.letsencrypt.acme.caServer=https://acme-staging-v02.api.letsencrypt.org/directory
- --certificatesresolvers.letsencrypt.acme.httpchallenge=true
- --certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=http
- --certificatesresolvers.letsencrypt.acme.email=${EMAIL}
- --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
labels:
# Redirect all HTTP traffic to HTTPS
- traefik.http.routers.to-https.rule=HostRegexp(`{host:.+}`)
- traefik.http.routers.to-https.entrypoints=http
- traefik.http.routers.to-https.middlewares=to-https
# Traefik dashboard router
- traefik.http.routers.traefik.rule=Host(`traefik.devqa.${DOMAIN}`)
- traefik.http.routers.traefik.entrypoints=https
- traefik.http.routers.traefik.service=api@internal
- traefik.http.routers.traefik.tls=true
- traefik.http.routers.traefik.tls.certresolver=${CERT_RESOLVER}
- traefik.http.middlewares.to-https.redirectscheme.scheme=https
- traefik.http.routers.api.tls.domains[0].main=${DOMAIN}
ports:
- 80:80
- 443:443
volumes:
- ./letsencrypt:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- spector-net
networks:
some-net:
driver: bridge
@Eragoo
Copy link
Author

Eragoo commented Dec 21, 2022

here is content of .env file:
DOMAIN=yourdomain.com
EMAIL=[email protected]
CERT_RESOLVER=letsencrypt

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