nginx: [emerg] host not found in upstream

I encountered the above error message on container start up when I was using the nginx docker image.
There are several answers to be found on the Internet in relation to this problem, but somehow none of them worked for my case.

I run the nginx docker command from command line like this:
docker run --name nginx -p 80:80 \ -v ${HOME}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \ -it --rm nginx:1.13

In my nginx.conf file I had my upstream defined like this:
 upstream authenticator {     
      server myserver;
    }

Where myserver was a separate internal host.
The suggested solution is to add a resolver directive to the config with the ip of the nameserver.

resolver 1.1.1.1;  upstream authenticator {     
      server myserver;
    }
That didn't work either.
After investigating the containers /etc/resolve.conf file I found that it points to 8.8.8.8 that is the google dns.
Because myserver is in fact an internal server it wouldn't resolve of course and seems that nginx docker by default won't pick up my resolver ip to resolve the host name.
I concluded that the solution was to add a switch to the docker command that pointed docker to my internal dns and that worked.
 docker run --name nginx -p 80:80 \ -v ${HOME}/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \ -it --rm --dns 1.1.1.1 nginx:1.13


References:

Comments

Popular posts from this blog

The biggest java security vulnerability of 2021