Local HTTPS During Development with Docker

When developing a Slack bot or some other webhook, an HTTPS connection is often required. This can make it hard to develop and test on your local machine.

For one project, I found myself pushing code to a test server every time I wanted to run it, which worked, but was annoying. So I went in search of a solution.

There are a thousand ways to solve this problem. One of the easiest is probably ngrok, but I found another nifty solution that is especially convenient if you are already running services in Docker. I’m going to describe each of the pieces, followed by a docker-compose file that sets them up.

1. Set Up an HTTPS Terminator/Proxy

The first step is getting something set up to handle the HTTPS termination. I have a couple of personal projects that use the docker/letsencrypt/nginx/proxy setup described here. It very conveniently sets up letsencrypt + nginx to terminate HTTPS connections, then forwards them as HTTP to other Docker containers.

2. Set Up Port Forward Server

Net, I set up another Docker container that just runs an SSH server, set up for reverse port forwarding. I can then set up the nginx proxy to forward a subdomain to that container, so https://dev.mydomain.com ends up getting proxied to an HTTP request to my ssh container.

3. Initiate Forwarding

Then, on my local machine, I start my webserver (say it’s running on port 8080), and I run something like:
ssh -g -R 80:localhost:8080 -p 2222 dev.mydomain.com

Now, if someone makes an HTTPS request to https://dev.mydomain.com, it gets turned into an HTTP request to port 8080 on my local machine.

Set Up Your Own

If you want to try it out, I have an example repo with a docker-compose file here.

Follow the instructions there. Once it’s started, you can run:

./start_tunnel.sh 8080 your.domain.com

and now you can debug HTTPS services locally, too! :)

I will not vouch for its production-readiness, but I’ve found it handy for development more than once.