How to install Nginx with SSL on Docker and encrypt running containers

4 comments
Now lets encrypt our sites with free SSL certificate. We need nginx proxy with letsencrypt companion that will automatically generate/renew SSL certificates for our sites, proxy requests from outside to docker containers. More details about nginx-proxy on docker hub.

Known limitation: for correct work of nginx-proxy all containers should be in same network as nginx-proxy. So from here we're going to use compose v1 syntax.

For correct work of letsencrypt companion we need open 80 port on our server.
docker-compose.yml
nginx-proxy:
  restart: on-failure:5
  image: jwilder/nginx-proxy:latest
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - ./certs:/etc/nginx/certs:ro
    - ./vhost.d:/etc/nginx/vhost.d
    - ./html:/usr/share/nginx/html
    - /var/run/docker.sock:/tmp/docker.sock:ro
  labels:
    - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"

nginx-proxy-companion:
  restart: on-failure:5
  image: jrcs/letsencrypt-nginx-proxy-companion
  volumes:
    - ./certs:/etc/nginx/certs:rw
    - /var/run/docker.sock:/var/run/docker.sock:ro
  volumes_from:
    - nginx-proxy

Run nginx-proxy:
 docker-compose up -d

Lets encrypt our Portainer container. First of all we need specify virtual host for which nginx will proxy requests, letsencrypt host we need SSL and letsencrypt email.
  environment:
    - "VIRTUAL_HOST=docker.example.com"
    - "VIRTUAL_PORT=9000"
    - "LETSENCRYPT_HOST=docker.example.com"
    - "LETSENCRYPT_EMAIL=email@example.com"

After portainer restart nginx proxy will generate SSL certificates for portainer and virtual host for proxying request.

4 comments :

  1. After a lead generation, the entire revenue goes to the course instructor. For instance, if a lead is generated through the coupon code given by the course creator, the instructor will get the revenue. office 365

    ReplyDelete
  2. Nice blog, it’s so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us. Keep Sharing.
    Digital Marketing Course In Kolkata
    Web Design Course In Kolkata

    ReplyDelete