Skip to content

host not found in up stream #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cedvdb opened this issue Oct 23, 2016 · 8 comments
Closed

host not found in up stream #127

cedvdb opened this issue Oct 23, 2016 · 8 comments

Comments

@cedvdb
Copy link

cedvdb commented Oct 23, 2016

I'm trying to run nginx as a reverse proxy inside docker. The issue is that nginx is exiting because it doesn't find the host in upstream (nginx strts faster than keycloak I assume) so it just exits.

docker compose

 version: '2'
 services:
  keycloak:
    image: jboss/keycloak-postgres
    ports:
      - "8080:8080"
  nginx:
    build:
      context: ./nginx
      dockerfile: dockerfile
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      - keycloak
    entrypoint: ['sleep', '25']
 > nginx conf
  server {
    listen 80;

    location / {
      index index.html;
      root /usr/share/nginx/html;
    }

    location /auth {
      proxy_pass http://keycloack:8080/auth;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
  }
@UpCoder
Copy link

UpCoder commented Nov 13, 2016

have you solved the problems? can you teach me ?thanks!

@stephanlindauer
Copy link

@cedvdb which version of docker-compose are you running? i think in older versions depends_on didn't link containers.

@andreif
Copy link

andreif commented Apr 11, 2017

Try adding networks, e.g.

version: '2'
networks:
  front:
  back:
services:
  keycloak:
    image: jboss/keycloak-postgres
    ports:
      - "8080:8080"
    networks:
      - back
  nginx:
    build:
      context: ./nginx
      dockerfile: dockerfile
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      keycloak:
        condition: service_started
    entrypoint: ['sleep', '25']
    networks:
      - front
      - back

Also maybe depends_on expects dictionary:

      keycloak:
        condition: service_started

@andreif
Copy link

andreif commented Apr 11, 2017

Sorry, I am blind, here is what my awesome colleague wrote to fix it:

    # nginx can't resolve hosts using resolv.conf, and one can't be sure
    # which IP address the nameserver has.
    command: [/bin/sh, -c,
      "export NAMESERVER=$$(cat /etc/resolv.conf \
        | grep 'nameserver' | awk '{print $$2}' | tr '\\n' ' ') && env \
      && echo Creating /etc/nginx/conf.d/resolver.conf \
      using nameserver $$NAMESERVER from /etc/resolv.conf \
      && echo 'resolver' $$NAMESERVER ';' > /etc/nginx/conf.d/resolver.conf; \
      (test -e /etc/nginx/conf.d/default.conf \
       && rm /etc/nginx/conf.d/default.conf); nginx -g 'daemon off;'"]

It would be awesome if Nginx did it natively.

@andreif
Copy link

andreif commented Apr 11, 2017

btw, is it alpine image?

@cedvdb
Copy link
Author

cedvdb commented Apr 12, 2017

@andreif I think the docker was an alpine image (I made this question 6 months ago). Thanks!

@cedvdb cedvdb closed this as completed Apr 12, 2017
@andreif
Copy link

andreif commented Apr 12, 2017

If it was alpine, then it's related to #78

@imarotte
Copy link

I'm having this exact issue. I have 4 computers at work running docker. 2 of them have this issue, two of them don't when running the exact same docker-compose. Any idea what could be causing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants