How to fix DNS Internal Resolution inside the Nginx docker container
Emmanuel Gautier / November 19, 2022
1 min read
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'
services:
containername:
...
container_name: containername
networks:
- intranet
nginx:
image: nginx:1
ports:
- "8080:8080"
volumes:
- ./.docker/nginx/conf.d:/etc/nginx/conf.d
networks:
- intranet
networks:
intranet:
And the Nginx configuration used:
server {
listen 8080;
listen [::]:8080;
server_name localhost;
location / {
proxy_pass http://containername:3000;
}
}
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 {
resolver 127.0.0.11;
}
Hope this quick post helps you fix a similar issue.
Consulting
If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.
Related Posts
How to solve Docker compose error ".labels array items must be unique"?
This blog post provides a clear understanding and a solution for the docker compose error `array items must be unique`.
MySQL Docker Image for Mac ARM M1
MySQL official Docker image is not available for Apple ARM-based M1 and M2 CPUs. But there is some options to use mysql image on Mac and more globally on ARMv8 microarchitecture.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
Featured Posts
Introducing new blog about OAuth, OpenID Connect, and IAM Solutions
I'm excited to announce the launch of a new blog named CerberAuth, where I'll be exploring the world of OAuth, OpenID Connect, and IAM solutions for modern security.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
How to enable Python type checking in VSCode
Python now has support for type hints. In this article, we will see how to enable better IntelliSense and type checking analysis in VSCode.