Git Product home page Git Product logo

letsencrypt-nginx-proxy-companion-compose's Introduction

Build Status

letsencrypt_nginx_proxy_companion with docker-compose

This repository contains reference docker-compose files for a variety of nginx-proxy with letsencrypt-nginx-proxy-companion setups :

.
├── 2-containers
│   ├── compose-v2
│   └── compose-v3
│       ├── environment
│       └── labels
└── 3-containers
    ├── compose-v2
    │   ├── environment
    │   └── labels
    └── compose-v3
        ├── environment
        └── labels

Before your start

Be sure to be familiar with the basic, non compose use of this container with nginx-proxy.

All the docker-compose file assume the existence of a docker network called nginx-proxy. You'll have to create it with docker network create nginx-proxy before you can use any of the example file.

For letsencrypt-nginx-proxy-companion to work properly, it needs to know the id of the nginx-proxy container, or the id of both the nginx and docker-gen containers in a three container setup.

If you start your stack using the docker run commands from the examples, the letsencrypt container will automatically find the id of the nginx (or nginx-proxy) container through the volume it gets with the --volumes_from option.

This options also exists in compose file version 2, but not on compose file version 3, meaning that if you use a version 3 file, it needs to use one the two ways to make the letsencrypt container aware of the nginx/nginx-proxy container id. Those two methodes are:

  • adding the label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxyto the nginx/nginx-proxy container.
  • assigning a fixed name to the nginx/nginx-proxy container with container_name: and setting the environment variable NGINX_PROXY_CONTAINER to this name on the letsencrypt container.

On a three container setup, the letsencrypt container has no automated way to get the id of the docker-gen container, so in this setup, you'll need to use one of those two methods (wether you use a compose file version 2 or 3):

  • adding the label com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gento the docker-gen container.
  • assigning a fixed name to the docker-gen container with container_name: and setting the environment variable NGINX_DOCKER_GEN_CONTAINER to this name on the letsencrypt container.

The docker-compose files on environment subfolders use the environment variable method.

The docker-compose files on labels subfolders use the label method.

The advantage the labels method has over the environment method is enabling the use of the letsencrypt-nginx-proxy-docker-companion in Swarm Mode or in Docker Cloud, where containers names are dynamic. Howhever if you intend to do so, as upstream docker-gen lacks the ability to identify containers from labels, you'll need both to use the three container setup and to replace jwilder/docker-gen with a fork that has this ability like herlderco/docker-gen. Be advised that for now, this works to a very limited extent (everything has to be on the same node).

As for the rest of the subfolders:

  • 2-containers are setup using nginx-proxy + letsencrypt_nginx_proxy_companion
  • 3-containers are setup using nginx + docker-gen + letsencrypt_nginx_proxy_companion
  • compose-v2 are compose file version 2 making use of volumes_from:
  • compose-v3 are compose file version 3

The simplest, most straightforward setup is two containers using compose file version 2.

Usage

  1. get the docker-compose.yaml corresponding to the setup you want to start from.
  2. if you use a three containers setup, don't forget to get the nginx.tmpl file and put next to the docker-compose.yaml file.
  3. create the required docker network with docker network create nginx-proxy.
  4. launch the stack in detached mode with docker-compose up -d

Once your nginx-proxy stack is up and running you can launch proxyed containers from the command line (don't forget to connect them to the nginx-proxy network):

docker run -d \
    --name example-webapp \
    --network nginx-proxy \
    --expose 80 \
    -e "VIRTUAL_HOST=subdomain.yourdomain.tld" \
    -e "VIRTUAL_PORT=80" \
    -e "LETSENCRYPT_HOST=subdomain.yourdomain.tld" \
    -e "[email protected]" \
    nginx

Or with a compose file:

version: '3'

services:
  web:
    image: nginx:alpine
    container_name: example-webapp
    expose:
      - "80"
    environment:
      - VIRTUAL_HOST=subdomain.yourdomain.tld
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=subdomain.yourdomain.tld
      - [email protected]
    restart: always

networks:
  default:
    external:
      name: nginx-proxy

In both case --expose (or expose:) and the VIRTUAL_PORT environment variable probably won't be required, but they are an added precaution toward a working setup if you use them correctly.

In any case all those compose files are mostly there to serve as "known working" base examples of a nginx-proxy + letsencrypt stack the way I use it, in a variety of setup. Do not hesitate to tinker and customise them to fit your particular need.

letsencrypt-nginx-proxy-companion-compose's People

Contributors

buchdag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

letsencrypt-nginx-proxy-companion-compose's Issues

Pi-hole / Three Container Setup

Hello Buchdag,

I hope you can help me with this problem. I am using the "three containers/compose-v3/labels"-setup you provided. It is a great setup, thanks to you!
It works fine with other kinds of projects, but when i tried to run Pi-hole behind it, Pi-hole crashed with the following output, even though I'am using the DEFAULT_HOST environment variable:

Removing pihole
Recreating d09f715ad0ee_pihole ...
Recreating d09f715ad0ee_pihole ... error

ERROR: for d09f715ad0ee_pihole  Cannot start service pihole: driver failed programming external connectivity on endpoint pihole (f99813b9aca1b4dce45dfc05fc7c52ca6685ea7e0d981e2d557786e3e258a529): Bind for 0.0.0.0:443 failed: port is already allocated

ERROR: for pihole  Cannot start service pihole: driver failed programming external connectivity on endpoint pihole (f99813b9aca1b4dce45dfc05fc7c52ca6685ea7e0d981e2d557786e3e258a529): Bind for 0.0.0.0:443 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

After trying many different ways of fixing this error, my last attempt was to use the basic/standard "jwilder/nginx-proxy" and et voilà it worked... :(
So I think I am missing somthing little, but I can't find it.

My ReverseProxy (based on your example) looks like this:

version: '3'
services:
  reverseproxy-nginx:
    image: nginx
    container_name: reverseproxy-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - certs:/etc/nginx/certs:ro
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
    environment:
      - TZ=Europe/Berlin
    restart: always

  reverseproxy-dockergen:
    image: jwilder/docker-gen
    command: -notify-sighup reverseproxy-nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    container_name: reverseproxy-dockergen
    depends_on:
      - reverseproxy-nginx
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - certs:/etc/nginx/certs:ro
      - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen"
    environment:
      - TZ=Europe/Berlin
      - DEFAULT_HOST=pihole.myadress.com
    restart: always

  reverseproxy-letsencrypt-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion:latest
    container_name: reverseproxy-letsencrypt-companion
    depends_on:
      - reverseproxy-nginx
      - reverseproxy-dockergen
    volumes:
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - certs:/etc/nginx/certs
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - TZ=Europe/Berlin
    restart: always

volumes:
  conf:
  vhost:
  html:
  certs:

networks:
  default:
    external:
      name: nginx-reverseproxy

My Pi-hole docker-compose.yml looks like this:

version: '3'

# https://github.com/pi-hole/docker-pi-hole/blob/master/README.md

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "80:80/tcp"
      - "443:443/tcp"
    environment:
      - TZ=Europe/Berlin
      - WEBPASSWORD=ReallySecurePasswordForPiHole
      - ServerIP=10.10.10.50
      - VIRTUAL_HOST=pihole.myadress.com
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=pihole.myadress.com
      - [email protected]
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole/:/etc/pihole/'
      - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
      # run `touch ./var-log/pihole.log` first unless you like errors
      # - './var-log/pihole.log:/var/log/pihole.log'
    dns:
      - 127.0.0.1
      - 1.1.1.1
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    #cap_add:
    #  - NET_ADMIN
    restart: always

networks:
  default:
    external:
      name: nginx-reverseproxy

I would appreciate any hint and/or help.
Thanks in advance!

Automatic port forwarding

Dear @buchdag,

i would like to come back to our discussion here:
buchdag/multiarch-letsencrypt-nginx-proxy#7 (comment)
I had no time till now thatswhy the late response.

I created now a script which i would like to place as well in the lets encrypt container and execute before the renewal start (to open the port forwarding) and again after the renewal was successfully (to close the port forwarding).

The only thing what i would like to know, is in which file/script and line exactly would you suggest to place in your scripts these explained execution command to run my script?

Thanks and Greetings

Daniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.