Warning
Before installation, we need to check ports, 443, 8080 and 80 are free
docker network create hostmanager && docker run -d --name traefik-docker-hostmanager --restart=always -v /var/run/docker.sock:/var/run/docker.sock -p 80:80 -p 443:443 -p 8080:8080 --network hostmanager mihani/traefik-docker-hostmanager- Create
hostmanagernetwork then run container
docker network create hostmanager- Create and run the container
- If you want container start when Docker Engine start run :
docker run -d --name traefik-docker-hostmanager --restart=always -v /var/run/docker.sock:/var/run/docker.sock -p 80:80 -p 443:443 -p 8080:8080 --network hostmanager mihani/traefik-docker-hostmanager- If not, run :
docker run -d --name traefik-docker-hostmanager -v /var/run/docker.sock:/var/run/docker.sock -p 80:80 -p 443:443 -p 8080:8080 --network hostmanager mihani/traefik-docker-hostmanagerYou can access to traefik dashboard with this url : https://traefikboard.localhost
By default, you didn't precise name for the default network and docker compose use default as name for network. Now we need to name you internal network and add hostmanager as external network.
networks:
internal-project-network-name:
name: internal-project-network-name
external: false
hostmanager:
external: trueYou need to add the previous networks on each container you need to detect by Traefik
networks:
- internal-project-network-name
- hostmanagerYou need to tell at Traefik which container needs routing from Traefik. Traefik use docker label system to recognize and redirect the request to the good service.
:rotating_light: On your host label, you need to keep the keywork localhost
labels:
- "traefik.enable=true"
- "traefik.http.routers.{service-name}.rule=Host(`custom-name.localhost`)"
- "traefik.http.routers.{service-name}.tls=true"The previous label is the minimum you need to use. Thanks to "traefik.http.routers.{service-name}.rule=Host(`custom-name.localhost`)" that add the url you will use to call the container in your web browser.
Example of service declaration with minimal information needed :
whoami:
image: whoami/image
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
- "traefik.http.routers.whoami.tls=true"
networks:
- hostmanager
- internal-project-network-name
# Rest of docker compose configurationNow you just need to call name use in Host rule to access at you container, in your favorite browser.