Traefik and docker-compose

January 24, 2018
Docker traefik

Using traefik with docker-compose

In this post, i will explain a real usecase i had with a customer. The purpose was to add https to their existing website (already running with Docker). Easy (for my part) but a part of the demand was to have only one docker-compose file for both dev and production (dev is made on developpers’ machines).

Here is the final config file (stripped down for the only usefull parts) :

version: 3.3
services:
	lb:
		image: traefik:1.5-alpine
   		restart: always
   		command: --web --acme.storage=/etc/traefik/acme.json --logLevel=info \
            		 ${TRAEFIK_ENTRYPOINT_HTTP} ${TRAEFIK_ENTRYPOINT_HTTPS}\
            		 --defaultentrypoints=${TRAEFIK_DEFAULT_ENTRYPOINTS} \
                         --acme=${ACME_ENABLE} --acme.entrypoint=https --acme.httpchallenge --acme.httpchallenge.entrypoint=http \
            		 --acme.domains="${ACME_DOMAINS}" --acme.email="${ACME_EMAIL}" \
            		 --docker --docker.domain="${DOCKER_DOMAIN}" --docker.endpoint="unix:///var/run/docker.sock" \
            		 --docker.watch=true --docker.exposedbydefault="false"
   		container_name: traefik
   		networks:
     			- core
   		ports:
     			- "80:80"
     			- "443:443"
     			- "8080:8080"
   		volumes:
     			- ./docker/traefik:/etc/traefik/
     			- /var/run/docker.sock:/var/run/docker.sock
     				
         web:
    		image: "customer/nginx"
    		container_name: web
    		depends_on:
      			- php
    		networks:
      			- core
    		volumes:
      			- ./src/:/var/www/
    		labels:
      			- "traefik.backend=nginx"
      			- "traefik.frontend.rule=Host:${TRAEFIK_HOST}"
      			- "traefik.port=80"
      			- "traefik.enable=true"

And now you will just have to create a .env file :

And that’s all !

Use constraints with Swarm

September 4, 2018
Docker

Setup a Let's encrypt certificate with Traefik

May 23, 2018
Docker traefik

Traefik for the beginners

May 4, 2018
Docker traefik