The Docker Compose file in this repository contains an instance of
Traefik for development purposes. It allows you to access
microservices through your browser using a hostname (such as
accounts.leviy.localhost) and to run multiple microservices at the same time
without port binding conflicts.
- Docker
- Docker Compose
- A DNS resolver that resolves any hostname ending in ".localhost" to 127.0.0.1 (see instructions)
git clone [email protected]:leviy/workspace.git
cd workspace
docker-compose up -dThe Docker Compose file contains the restart: always directive so Docker will
restart the container every time you boot your machine. If for some reason you
need to start another container or project that needs to bind to port 80, you
can stop the containers using:
docker-compose stopWhen the containers are running, the Traefik dashboard can be found at
http://localhost:8080/dashboard/. Other microservices can register themselves to
Traefik by adding the following to their docker-compose.yml:
version: '3'
services:
microservice-name:
image: nginx
networks:
- workspace
- default
labels:
traefik.frontend.rule: Host:subdomain.leviy.localhost
traefik.enable: 'true'
networks:
workspace:
external:
name: workspace_defaultWeb server services that should be reverse proxied should be linked to both the
workspace network and the default network of that Docker Compose project.
Non-web services (such as databases, etc.) should only be linked to the
default network.
When started, Traefik will automatically detect this service and start routing
traffic to it.
To see it in action simply open http://subdomain.leviy.localhost in a
browser.