Renseigner l’adresse de mon site à tester dans le fichier host C:\Windows\System32\drivers\etc

Test de jwilder/nginx-proxy sans SSL

$ docker run -d -p 80:80 /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

Lors du lancement d’un conteneur renseigner le sous domaine pour mapper le conteneur

$ docker run -e VIRTUAL_HOST=foo.bar.fr  ...

Test en local sans SSL avec conteneur apache :

$ sudo docker run -e VIRTUAL_HOST=foo.bar.fr -p 8003:80 httpd:latest

Multiple Networks

To attach to other networks, you can use the docker network connect command after your container is created:

$ docker network connect my-other-network my-nginx-proxy

Tutoriel SSL with let’s encrypt companion

Step 1 - nginx-proxy

Start nginx-proxy with the three additional volumes declared:

$ docker run --detach \
    --name nginx-proxy \
    --publish 80:80 \
    --publish 443:443 \
    --volume /etc/nginx/certs \
    --volume /etc/nginx/vhost.d \
    --volume /usr/share/nginx/html \
    --volume /var/run/docker.sock:/tmp/docker.sock:ro \
    jwilder/nginx-proxy

Step 2 - letsencrypt-nginx-proxy-companion

Start the letsencrypt-nginx-proxy-companion container, getting the volumes from nginx-proxy with --volumes-from:

$ docker run --detach \
    --name nginx-proxy-letsencrypt \
    --volumes-from nginx-proxy \
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \
    --env "DEFAULT_EMAIL=mail@yourdomain.tld" \
    jrcs/letsencrypt-nginx-proxy-companion

Step 3 - proxyed container(s)

Once both nginx-proxy and letsencrypt-nginx-proxy-companion containers are up and running, start any container you want proxyed with environment variables VIRTUAL_HOST and LETSENCRYPT_HOST both set to the domain(s) your proxyed container is going to use.

$ docker run --detach \
    --name your-proxyed-app \
    --env "VIRTUAL_HOST=subdomain.yourdomain.tld" \
    --env "LETSENCRYPT_HOST=subdomain.yourdomain.tld" \
    nginx

The containers being proxied must expose the port to be proxied, either by using the EXPOSE directive in their Dockerfile or by using the --expose flag to docker run or docker create.

If the proxyed container listen on and expose another port than the default 80, you can force nginx-proxy to use this port with the VIRTUAL_PORT environment variable.

Example using Grafana (expose and listen on port 3000):

$ docker run --detach \
    --name grafana \
    --env "VIRTUAL_HOST=othersubdomain.yourdomain.tld" \
    --env "VIRTUAL_PORT=3000" \
    --env "LETSENCRYPT_HOST=othersubdomain.yourdomain.tld" \
    --env "LETSENCRYPT_EMAIL=mail@yourdomain.tld" \
    grafana/grafana

Repeat Step 3 for any other container you want to proxy.

Editer les variables ENV d’un conteneur sans re-run et perdre la conf du container

  1. Stop docker deamon with cmd : docker service stop

  2. Edit : /var/lib/docker/containers/[container-id]/config.json

  3. Start docker deamon again with cmd : docker service start

  4. Check if your container ENV variables have been updated :)

Really handy ! Changes are permanent now if you restart the container.

Seul soucis, il faut stop le deamon docker pendant la manip ce qui redemarre revient à faire un restart de tous les conteneurs !