1

Currently I have 2 Docker containers:

  • Application (python flask)
  • Load Balancer (nginx)

I'm starting both containers separately with docker-composer up Nginx is listening in port 8080 and should forward HTTP requests to application which is listening to port 8081. Currently this is not working as nginx doesnt know anything about the application container.

86615a5b0f02        parzee/loadbalancer   "/usr/local/bin/start"   3 minutes ago       Up 3 minutes        127.0.0.1:8080->8080/tcp   loadbalancer_loadbalancer_1
9adc8a04b356        parzee/application    "/usr/local/bin/start"   6 minutes ago       Up 5 minutes        127.0.0.1:8081->8081/tcp   application_application_1

This is my default configuration

upstream application {
    ip_hash;
        server application_application_1:8081 fail_timeout=0;
        server application_application_2:8081 fail_timeout=0;
    keepalive 64;
}

server {
    listen 8080;
    server_name loadbalancer;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;

    #Timeout after 8 hours
    proxy_read_timeout 43200000;
    proxy_connect_timeout 43200000;

        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://application;
            break;
        }
    }
}

I get:

2016/02/15 08:42:07 [emerg] 21#0: host not found in upstream "application_application_1:8081" in /etc/nginx/sites-enabled/default:3
2016/02/15 08:42:10 [emerg] 22#0: host not found in upstream "application_application_1:8081" in /etc/nginx/sites-enabled/default:3

How to define my nginx configuration by either using hosts or IP addresses? I haven't used IP addresses as docker may assign different IPs from a known range. Any suggestions? Should I start all of them in a single docker-compose.yml file?

1

did you define a link to application_application_1 in your docker-compose.yml file?

0

Links did the trick:

database:
  image: parzee/database
  volumes_from:
    - dbdata
  ports:
    - "5432:5432"

# RABBITMQ TCP:5672
rabbitmq:
  image: parzee/rabbitmq-server
  hostname: rabbitmq
  ports:
    - "5672:5672"
    - "15672:15672"

# LIGHTTPD TCP:8083
lighttpd:
  image: parzee/lighttpd
  hostname: lighttpd
  ports: 
    - "8083:8083"
  volumes:
    - /usr/local/src/containers/application/volumes/imbue/:/usr/local/src/imbue/application/imbue/utils/security/des/
    - /usr/local/src/containers/lighttpd/volumes/log/:/var/log/lighttpd/ 

# APPLICATION TCP:8081
application_1:
  image: parzee/application
  hostname: application_1
  links:
        - database:database
        - lighttpd:lighthttpd
        - rabbitmq:rabbitmq

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.