Question

What value should I use for Nginx proxy_pass running in Docker?

I have a fresh Droplet on Ubuntu 16.04 running Docker and Docker Compose with two containers: nginx and my homepage.

My homepage container is running on port 3000. I can curl localhost:3000 and see the app.

I have this setup on my home server and on AWS and the proxy_pass value is the local/private IP address of my server. For example on my home server it’s http://192.168.1.100:3000/, on AWS it’s the Private IP of the EC2 instance.

I have tried several values on the Droplet for proxy_pass such as http://127.0.0.1:3000, localhost, but none of those worked. I lastly tried enabling private networking and tried using the listed private IP address. Still nothing…

What should I be using for the value here?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Accepted Answer

My apologies if this is against the rules to post an answer to your own question, but many times in the past I’d wished others had done the same.

For those that weren’t aware, whenever you use docker-compose up, it automatically creates a default docker network if you don’t specify any in the docker-compose.yaml. Docker containers in the same network automatically get a DNS entry created for the container name. That means you can access the other containers in the network using something like http://mycontainername:8080.

For the Nginx container running the reverse proxy, the proxy_pass value ended up just being http://myapp:3000.

Definitely seems like a no-brainer. I know I had seen posts online regarding using a name url like that but was ignoring all them because I didn’t realize the docker network was doing that behind the scenes and din’t put it together that using the container name would work in this way.

Hopefully this helps someone!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel