A configuration set-up for a Traefik v2 reverse proxy along with Portainer and Docker Compose.
This set-up makes container management & deployment a breeze and the reverse proxy allows for running multiple applications on one Docker host. Traefik will route all the incoming traffic to the appropriate docker containers and through the open-source app Portainer you can speed up software deployments, troubleshoot problems and simplify migrations.
apt update && apt upgrade
apt install apt-transport-https ca-certificates curl software-properties-common && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
Make sure we are installing it from docker:
apt-cache policy docker-ce
apt install docker-ce
Testing installation:
systemctl status docker
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
git clone https://github.com/dbartumeu/docker-traefik-portainer ./src && cd src/core
Make sure your server has htpasswd installed. If it doesn’t you can do so with the following command:
sudo apt-get install apache2-utils
Then run the below command, replacing the username
and password
with the one you want to use.
echo $(htpasswd -nb <username> <password>)
Edit the .env
file and add your auth string to TRAEFIC_AUTH
. Also replace ACME_EMAIL
, TRAEFIC_HOST
and PORTAINER_HOST
with your own values.
source .env
docker network create proxy
sudo chmod 600 ./traefik-data/acme.json
sudo docker-compose up -d
Using Create stack in portainer copy and paste the dockerfile and make sure to include in the dockerfile:
services:
...
networks:
- proxy
- default
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.myservice.entrypoints=websecure"
- "traefik.http.routers.myservice.rule=Host(`myservice.yourdomain.com`)"
- "traefik.http.services.myservice.loadBalancer.server.port=myserviceport"
networks:
proxy:
external: true
default:
Make sure to change myservice
, myservice.yourdomain.com
and myserviceport
for meaningful values.