If you want to define several containers and also get them up and running, docker-compose is an efficient tool.
First, you need to kick things off with a config file (docker-compose.yml) that encompasses images for both Nginx and certbot.
version: ‘3’
services:
nginx:
image: nginx:1.15-alpine
ports:
– “80:80”
– “443:443”
volumes:
– ./data/nginx:/etc/nginx/conf.d
certbot:
image: certbot/certbot
Next, you can use this basic configuration to point incoming requests to HTTPS. Just swap in your domain name there the example URLs are found. Then, save the domain name as data/nginx/app.conf.
server {
listen 80;
server_name example.com; location / {
return 301 https://$host$request_uri;
}
}server {
listen 443 ssl;
server_name example.com;
location / {
proxy_pass http://example.com;
}
}
Joining the dots
In order to validate domains, Let’s Encrypt request-response data from certbot which has to be served files via the Nginx container. This takes a parallel approach to that used by Google Search Console.
Volumes for both validation challengers and certificates need to be added as follows within docker-compose.yml:
./data/certbot/conf:/etc/letsencrypt
./data/certbot/www:/var/www/certbot
Then to the certbot section you need to include:
volumes:
./data/certbot/conf:/etc/letsencrypt
./data/certbot/www:/var/www/certbot
Subsequently you will need to place this in data/nginx/app.conf:
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
Now comes the time to bring the HTTPS certificates into play. Pop this, along with its key, into port 443. Remember to swap in your domain where appropriate:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
Finally, endow your config file with this HTTPS setup used by Let’s Encrypt to keep things consistent:
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;