Skip to content

Instantly share code, notes, and snippets.

@Akronae
Created July 6, 2022 13:55
Show Gist options
  • Save Akronae/024847a85887b5a43790a655f02c08a7 to your computer and use it in GitHub Desktop.
Save Akronae/024847a85887b5a43790a655f02c08a7 to your computer and use it in GitHub Desktop.
Traefik Docker Swarm Routing
# using the sample command "docker stack deploy -c=docker-compose.yml stack_name"
# will deploy all the below services accross all of your machines, route them together, auto-scale and load-balance them.
version: "3.3"
services:
api:
image: "registry.app-maville.com/api"
build: "./api"
env_file:
- ./var.env
networks:
- traefik-public
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.rule=Host(`api.app-maville.com`)"
- "traefik.http.services.api.loadbalancer.server.port=80"
- "traefik.http.routers.api.entrypoints=websecure"
- "traefik.http.routers.api.tls.certresolver=myresolver"
www:
image: "registry.app-maville.com/www"
build:
context: "."
dockerfile: "Dockerfile.www"
env_file:
- ./var.env
networks:
- traefik-public
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.www.rule=Host(`www.app-maville.com`) || Host(`app-maville.com`)"
- "traefik.http.routers.www.entrypoints=websecure"
- "traefik.http.routers.www.tls.certresolver=myresolver"
- "traefik.http.services.www.loadbalancer.server.port=80"
db:
image: "registry.app-maville.com/db"
build: "db"
env_file:
- ./var.env
volumes:
- /docker-volumes/db/:/var/lib/postgresql/data/
networks:
- traefik-public
deploy:
placement:
constraints:
- node.labels.static_files_host == true
labels:
- traefik.enable=true
- traefik.tcp.routers.db.entrypoints=postgres
- traefik.tcp.routers.db.rule=HostSNI(`*`)
- traefik.tcp.routers.db.service=db
- "traefik.docker.network=traefik-public"
- traefik.tcp.services.db.loadbalancer.server.port=5432
registry:
image: registry
volumes:
- /docker-volumes/registry:/docker-volumes/registry
environment:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /docker-volumes/registry/images
networks:
- traefik-public
deploy:
placement:
constraints:
- node.labels.static_files_host == true
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-public"
- "traefik.http.routers.registry.rule=Host(`registry.app-maville.com`)"
- "traefik.http.routers.registry.entrypoints=websecure"
- "traefik.http.routers.registry.tls=true"
- "traefik.http.routers.registry.tls.certresolver=myresolver"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
- "traefik.frontend.auth.basic=user:root:<hash_password>"
networks:
traefik-public:
external: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment