Skip to main content
Configure SSL for Docker

Setup SSL for your Docker using Nginx proxy

Kendis Team avatar
Written by Kendis Team
Updated over a week ago

**** This is NOT help article for general Docker and SSL Setup, it's only specific to Kendis *****

Once you have installed Kendis Docker and it's up and running, you can follow these steps to configure SSL.

Step 1: Create Directory

Create a directory with the name "docker_ssl_proxy" to store the NGINX configuration file and the certificate and key

 $ mkdir docker_ssl_proxy

Step 2: Change directory to docker_ssl_proxy

You must be under this directory before executing the following steps (commands).

Step 2.a: Use Signed certificates

If you have certificates you can simply copy the following 2 files in the current directory

Step 2.b Create the self-signed certificates (If needed)

Use OpenSSL to create a self-signed certificate, Following command will create a self-signed certificate and a private key with a validity of 365 days.

 $ openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365

Step 3: Find your container IP address

3.1: Find your kendis container Id. 

$ docker ps

It will list all the processes that are running and find out your Kendis container id.

3.2 Find IP Address

To find the container IP address from the host, you can run the command

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'  <kendis-contrainer-id>

<kendis-container-id>: replace this with the value that you get from Step 3.1

The response of the above command will be an IP address, e.g., 


Step 4: Create the NGINX configuration file

In the same directory (docker_ssl_proxy), create a configuration file that will proxy all the traffic to your upstream server. The upstream server is the application server running a non-SSL connection. The SSL will be using NGINX, and all the traffic will be proxied to the host (using the IP address that you got in Step 3.2)

The configuration file, which in this example is called "proxy_ssl.conf," but can have any name as long as it ends in .conf. The file must have the following contents

Example file: proxy_ssl.conf

server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/conf.d/cert.pem;
ssl_certificate_key /etc/nginx/conf.d/key.pem;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;

The only thing you need to replace in this file is IP Address. We are using the example IP

Please note, port shouldn't be changed, it must remain as 8080.

This file simply instructs NginX to listen, with SSL and the correct certs and keys, on port 443 and to proxy all the requests to the host on port 8080

Step 5: Run the docker container

At this point, we have all the configuration in place to proxy the traffic; we simply need to run the docker container with the following command.

$ docker run --name nginx_proxy -d -v pwd:/etc/nginx/conf.d -p 443:443 nginx

NOTE: If you face issues, try to replace PWD in the command above with the full directory path for "docker_ssl_proxy", where you have config and cert files. 

$docker run --name nginx_proxy -d -v <yourdirectory>:/etc/nginx/conf.d -p 443:443 nginx

All Done. 

Just open a browser and hit the URL with HTTPS.

Did this answer your question?