Created
March 25, 2020 16:25
-
-
Save alfredfrancis/14f60b4c3edd7707230c8005035bd151 to your computer and use it in GitHub Desktop.
Service Discovery and Reverse Proxy for Docker-based Microservices using Traefik
This file contains 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' | |
services: | |
reverse-proxy: | |
# The official v2 Traefik docker image | |
image: traefik:v2.1 | |
# Enables the web UI and tells Traefik to listen to docker | |
command: | |
- --api.insecure=true | |
- --api.dashboard=true # <== Enabling the dashboard to view services, middlewares, routers, etc... | |
- --api.debug=true # <== Enabling additional endpoints for debugging and profiling | |
- --log.level=DEBUG # <== Setting the level of the logs from traefik | |
- --providers.docker=true # <== Enabling docker as the provider for traefik | |
- --providers.docker.network=bots # <== Operate on the docker network named web | |
- --providers.docker.exposedbydefault=false # <== Don't expose every container to traefik, only expose enabled ones | |
ports: | |
# The HTTP port | |
- "80:80" | |
# The Web UI (enabled by --api.insecure=true) | |
- "8080:8080" | |
volumes: | |
# So that Traefik can listen to the Docker events | |
- /var/run/docker.sock:/var/run/docker.sock | |
networks: | |
- bots # <== Placing traefik on the network named bots, to access containers on this network | |
whoami: | |
# A container that exposes an API to show its IP address | |
image: containous/whoami | |
labels: | |
- "traefik.enable=true" # <== Enable traefik on itself to view dashboard and assign subdomain to view it | |
- "traefik.http.services.whoami.loadbalancer.server.port=80" | |
- "traefik.http.routers.whoami.rule=PathPrefix(`/bots/whoami`)" | |
networks: | |
- bots # <== Placing traefik on the network named bots, to access containers on this network | |
networks: | |
bots: | |
external: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment