DEV Community 👩‍💻👨‍💻

Emmanuel Gautier
Emmanuel Gautier

Posted on • Originally published at on

How to fix DNS Internal Resolution inside the Nginx docker container

Sometimes, errors with Docker and some containers can become cryptic when it is about networking. Today, it was Nginx that was not able to reach another container. Here is the docker-compose used:

version: '3'

    container_name: containername
      - intranet

    image: nginx:1
      - "8080:8080"
      - ./.docker/nginx/conf.d:/etc/nginx/conf.d
      - intranet

Enter fullscreen mode Exit fullscreen mode

And the Nginx configuration used:

server {
    listen       8080;
    listen  [::]:8080;
    server_name  localhost;

    location / {
        proxy_pass http://containername:3000;
Enter fullscreen mode Exit fullscreen mode

Even after defining a container name and ensuring that the two containers can communicate inside the same docker network, Nginx continues throwing the following error: no resolver defined to resolve container_name

Thanks for this Stack Overflow answer for helping me figure out what was the root cause. The problem is that Nginx's default behavior is not to make a DNS resolution with Docker's internal DNS so he can not resolve a container by name. To fix this issue, you need to make possible the resolution with the Docker internal DNS. Just add this line in the Nginx configuration and you should be OK:

http {
Enter fullscreen mode Exit fullscreen mode

Hope this quick post helps you fix a similar issue.

Top comments (0)

Create an Account!
Now it's your turn!
🗒 Share a tutorial
🤔 Reflect on your coding journey
❓ Ask a question

Create an account to join hundreds of thousands of DEV members on their journey.