How to run stand-alone traefik with multiple domains
I want to run two Drupal projects with docker4drdupal with stand-alone trefik container.
I was doing this by the instructions:
https://wodby.com/docs/stacks/drupal/local/#single-port
https://docs.traefik.io/getting-started/quick-start/
I had this structure:
- /var/www/project1
- — docker-compose.yml
- /var/www/project2
- — docker-compose.yml
- /var/www/traefik
- — docker-compose.yml
I comment out a traefik container in both project’s docker-compose files:
# traefik:
# image: traefik
# container_name: "${PROJECT_NAME}_traefik"
# command: -c /dev/null --web --docker --logLevel=INFO
# ports:
# - '8000:80'
## - '8080:8080' # Dashboard
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock
After that, I ran both projects without traefik containers.
cd /var/www/project1
docker-compose up -d cd /var/www/project2
docker-compose up -d
Then I started writing a docker-compose.yml file for traefik. Let me explain how I was writing that.
In first step I ran the command
docker network ls
And there I found that Docker created two networks after I ran these two projects:
project1_default
project2_default
So I can use them in for my traefik container.
I wrote this file: /var/www/traefik/docker-compose.yml
version: ‘3’services:
traefik:
image: traefik:v2.0
command: — api.insecure=true — providers.docker
networks:
— project1_default
— project2_default
ports:
— ‘80:80’
— ‘443:443’
— ‘8080:8080’
volumes:
— /var/run/docker.sock:/var/run/docker.socknetworks:
project1_default:
external:
name: project1_default
project2_default:
external:
name: project2_default
and ran it
cd /var/www/traefik
docker-compose up -d
After all I wanted to check is it working, so I go to
http://localhost:8080/api/rawdata
And there I found something like this:
routers:
...
nginx-project1@docker
service: "nginx-project1"
rule: "Host(`nginx-project1`)"
status: "enabled"
using:
0: http
1: traefik
Now we know the domain for first project. Let’s go to /etc/hosts
sudo nano /etc/hosts
and write there this line with the host from http://localhost:8080/api/rawdata
127.0.0.1 nginx-project1
and save it.
Then we can go to http://nginx-project1 url in browser and see our project1.