How to run several docker-compose projects with their traefik in each on the same server
The configuration is simple, for each project a docker-compose project name and port should be defined. It can be done with .env files.
COMPOSE_PROJECT_NAME=project1
PORT=8081
Docker compose will use COMPOSE_PROJECT_NAME variable as a prefix for the names of the containers.
Then in docker-compose.yml, these variables can be used to define the port mapping and the traefik constraints.
services:
traefik:
image: "traefik:v2.1.7"
command:
...
- "--providers.docker.constraints=Label(`com.docker.compose.project`, `${COMPOSE_PROJECT_NAME}`)"
ports:
...
- "${PORT}:80"
This can be used to run different projects or several instances of one project to test different branches.