Docker local server with HTTPs

Hello, I am trying to create a local docker server for a project. I am using the nginx docker image and utilizing the nginx web server inside of docker inside my local environment. I would like to know how I can keep nginx local to my machine, without having to port forward content to the internet. In addition, I want to encrypt the nginx web page by any means necessary if anyone knows a method.

I watched a tutorial on it but it wasn’t quite clear. I created a subdomain on duckdns but I wasn’t sure how to utilize it as duckdns has an api key. I am accessing the server on my local machine as I exposed port 80 on the container to a port on my machine and I access it in my browser via: http://localhost:port#.

I am not too familiar with how docker works all that well, I’m just trying to create a web server that I can access in my local environment and encrypt the default nginx page if possible.

I’m using Docker hub btw!

https/TLS/SSL usually uses domain names for the certificates. Using local IPs or localhost therefore doesn’t really work.

You can create your own certs manually or let a reverse proxy like Traefik do it for you, but they are not trusted by the browser, so you would need to click “risk and accept” or import them locally.

If you do have a domain with a DNS provider, you can use LetsEncrypt to create certificates, with dnsChallenge the domain target IP doesn’t even have to be reachable on the Internet. But you need a DNS registrar that is supported by tools like certbot, lego or acme.sh. Then you can point you public DNS to your private IP (no one else can access it) or add it to your home router or hosts file.

When you want the Docker container only to be accessible on the node itself, you can use ports: 127.0.0.1:80:80 to only bind to localhost and expose the port.