Last active
April 15, 2024 17:00
-
-
Save bestrocker221/7e783ae8cd1aa785416a662a01a9e8bd to your computer and use it in GitHub Desktop.
Example for Traefik + internal docker networks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.8' | |
services: | |
traefik: | |
image: traefik | |
container_name: traefik | |
security_opt: | |
- no-new-privileges:true | |
ports: | |
- "80:80" # Expose port 80 for incoming HTTP traffic | |
- "8080:8080" # Expose 8080 for dashboard (dev only) | |
networks: | |
- net-exposed # network with internet access | |
- net-proxy # network internal - no internet access (used only to route to project exposed ports) | |
- net-proxy2 | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
- ./logs/:/logs/ | |
- ./traefik.yml:/traefik.yml:ro # Bind mount the static configuration file | |
environment: | |
- TZ=Europe/Stockholm | |
nginx1: | |
image: nginx:alpine | |
container_name: nginx1 | |
networks: | |
- net-proxy # internal network used only by traefik, to route external visitors | |
- net-internal1 # network for intra container communication, i.e. DB, message queue, redis etc | |
labels: | |
- "traefik.enable=true" # Enable routing by Traefik | |
- "traefik.http.routers.nginx1.rule=Host(`nginx1.deb.ca.local`)" # Replace with your domain | |
- "traefik.http.routers.nginx1.entrypoints=web" # Entrypoint to use, here web for port 80 | |
- "traefik.http.routers.nginx1.service=app1" # Name the service | |
- "traefik.http.services.app1.loadbalancer.server.port=80" # Nginx listens on port 80 | |
- "traefik.docker.network=net-proxy" # Specifies which network traefik should use for routing | |
environment: | |
- TZ=Europe/Stockholm | |
nginx2: | |
image: nginx:alpine | |
container_name: nginx2 | |
networks: | |
- net-proxy2 | |
- net-internal2 | |
labels: | |
- "traefik.enable=true" | |
- "traefik.http.routers.nginx2.rule=Host(`nginx2.deb.ca.local`)" # Replace with your domain | |
- "traefik.http.routers.nginx2.entrypoints=web" | |
- "traefik.http.routers.nginx2.service=app2" | |
- "traefik.http.services.app2.loadbalancer.server.port=80" | |
- "traefik.docker.network=net-proxy2" | |
environment: | |
- TZ=Europe/Stockholm | |
networks: | |
net-exposed: # only network with internet access (able to expose ports on the host) | |
net-proxy: | |
internal: true # used only to route traefik <--> containers | |
external: true #must not be created by compose ( docker network create --internal net-proxy ) | |
net-proxy2: | |
internal: true # used only to route traefik <--> containers | |
external: true #must not be created by compose ( docker network create --internal net-proxy ) | |
net-internal1: | |
internal: true | |
net-internal2: | |
internal: true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment