Nginx image with certbot to automatically provision TLS certs for your dockerized applications.
Domain mapping. The domain name that will be used should already be bound with the Public IP address that is reachable to the docker host.
| Name | Description |
|---|---|
| SERVER_NAME | Domain name |
| UPSTREAM_URL | Where to forward the traffic to (application url) |
| CERTBOT_EMAIL | (Optional) to get certificate renewal alerts |
Initial / temp mount point -> /tmp/conf.d
This is only used in the initial run of the server.
The name of the initial nginx config file should be site.conf
After that, the nginx configs all stay in /etc/nginx.
It is recommended to mount the /etc/nginx dir to a docker volume. If you want more visible logging, you should mount the log dir at /var/log/nginx.
After the /etc/nginx directory is mounted, the certbot process won't run again (certificates won't be recreated) until the volume is wiped.
Both certbot-nginx and your application should be inside a user-defined docker bridge to allow them to communicate each other with container name.
Create Network and Volume
docker network create web
docker volume create certbot-nginx
Run your application
docker run -d --name app \
--network web \
docker.io/you/yourapp
Create nginx config in ./conf.d/site.conf
server {
listen 80;
server_name {env.SERVER_NAME};
access_log /var/log/nginx/app.access.log;
error_log /var/log/nginx/app.error.log;
location / {
proxy_pass {env.UPSTREAM_URL};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Run certbot-nginx
docker run -d --name certbot-nginx \
-v ./conf.d:/tmp/conf.d \
-v certbot-nginx:/etc/nginx \
--network web \
-p 80:80 \
-p 443:443 \
-e SERVER_NAME=app.example.com \
-e UPSTREAM_URL=http://app:3000 \
docker.io/fureasu346/certbot-nginx:v1
Content type
Image
Digest
sha256:1b2091319…
Size
27.8 MB
Last updated
9 months ago
docker pull fureasu346/certbot-nginx:v1