How to view docker nginx container through domain name?

Posted June 4, 2020 4.6k views

Hi guys,

As the question states I would like for when users browse to my domain name they see my nginx container. Currently I can view the container (default nginx) when I browse to my droplets ip but not through the domain name. I know my domain name is pointing to my droplet correctly since performing tracerts/pings result in a connection to my droplets ip.

My setup has been this:

  1. launch ubuntu droplet
  2. install docker
  3. pull nginx image and run it with -p 80:80

runing docker ps results in:
a7d45cc55a85 nginx “nginx -g ‘daemon of…” 8 minutes ago Up 8 minutes>80/tcp

This has resulted in the display of the 'Welcome to nginx’ page when I browse to my server ip, but when I browse to my domain I get ERRCONNECTIONREFUSED, “This site can’t be reached”.

Any help would be much appreciated.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

So I actually figured it out eventually. I have a .dev domain, and what was happening is every time I would go to it would always attempt to go to so I solved the problem by adding an ssl certificate to my nginx config.