Within a docker container I have a development server running that runs at:

Via nginx I am trying to make a request to this server:


upstream service_rest {
    server restapi:8000;

server {

    location /rest/ {
        proxy_pass http://service_rest;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;

My understanding would be this:

  1. When I type localhost:9000/rest/ (port 9000 is exposed to my host machine and mapped to the nginx docker service) nginx looks upstream to the service_rest server on port 8000 --> this part works
  2. service_rest:8000 automatically "knows" that the request is for the development server running on inside the container

Here is the problem, though: I don't think the requests are ever passed to the server running on

I recieve the following message as a log:

nginx_1 | 2019/05/11 07:49:06 [error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server: , request: "GET /rest/admin/ HTTP/1.1", upstream: "", host: "localhost:9000" (ip of container in bridge network) obviously is not equal to even though I sort of thought they were?

I am quite new to docker and nginx and a little confused about this. Can you guys help?


For interested parties:

The trick was to not have the development server run on localhost but instead on:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.