Docker: Jenkins, Nginx and Let’s Encrypt auto creation/renewal

Today I’ve spent a few hours (ok, like six hours to be honest) to figure out how to get letsencrypt-nginx-proxy-companion work with oficial jenkins image and docker-compose. Although the readme points to an example of the config I was interested in, it seems to be outdated or I’m just doing something wrong. The problem is, that I wasn’t able to pass Jenkins  VIRTUAL_PORT to nginx config, so I kept seeing 502 Bad Gateway when I tried to reach Jenkins UI. Although I specified it in the environment vars. Meh. Strange thing is, that it actually worked  when I launched Jenkins container with docker run.

Anyway, I needed any solution at the end of the day, even if it wouldn’t be the one that uses docker-compose.


First I followed the instructions from here. And to spin up Jenkins container I created a shell script with following code:

docker run -d \
--name jenkinsci \
--expose 8080 \
-p 8080:8080 \
-p 50000:50000 \
-e \
-e VIRTUAL_PORT=8080 \
-v /absolute/path/to/jenkins_home:/var/jenkins_home \
--network=webproxy \

Make the script executable:

chmod +x

and you are good go. Be sure that jenkins_home directory on the host is writable by the nginx user, otherwise it will remain empty and you’ll wonder where is yours jenkins_home/secrets/initialAdminPassword.