Ruby + Nginx not working

support

#1

So i’m trying to run a Ruby on Rails container to be accessed through the public URL, which means I need either to run it on port 80 or use Nginx (or similar tool) to redirect calls on port 80 to the port used in the Rails container, I’m trying using Nginx but haven’t been able to make it run, I get the error:

failed (111: Connection refused) while connecting to upstream, client: 52.4.252.97, server: ruby_test, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:3000/"

My docker-compose file looks like:

version: '2'
services:
  ruby_test:
    build: ./ruby_test
    privileged: true
    expose:
      - "3000"
  nginx:
    build: ./nginx
    depends_on:
      - ruby_test
    ports:
      - "80:80"

My nginx.conf file looks like:

events {
    worker_connections  1024;
}


http {
    upstream ruby_test {
        server 0.0.0.0:3000;
      }

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  ruby_test;

        location / {
            proxy_pass http://ruby_test;
            #root   html;
            #index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    include servers/*;
}

… I know the rails container is runing well on port 3000 because I can curl localhost:3000 and get the response expected.

Also I know nginx.conf file is fine give I tried it locally ad it works.

Ant ideas what am I missing?


Multicontainer networking between containers
#5

Hi,
I think the in the nginx configuration you need to change:

upstream ruby_test {
   server 0.0.0.0:3000;
}

to

upstream ruby_test {
   server ruby_test:3000;
}

Because the IP 0.0.0.0 is a special IP address not intended as a target address. Since you linked the ruby_test container to the nginx container the ruby_test container should be resolvable as ruby_test to the docker internal IP address from the nginx container.

Cheers
Andreas


#6

I feel embarrassed, how did I miss this… and YES IT WORKED… thanks a lot!!!