Understanding the Problem
The core of the problem lies in DNS resolution within Docker’s internal network. Normally, Docker handles DNS resolution for container names, allowing containers to communicate using these names. However, specific configurations can disrupt this, such as:
- Disabling the systemD resolver.
- Conflicts introduced by NginXManager.
The symptom? An Nginx container failing to resolve other container names, defaulting to an external DNS server (like 1.1.1.1).
Step-by-Step Solution
1. Check Docker Network Configuration
Ensure all containers are on the same Docker network. This can be a default bridge network or a custom network. Create and attach your containers to this network for internal name resolution.
docker network create my-network
docker run --network=my-network my-container
2. Adjust Nginx Resolver Configuration
Nginx may need a specific resolver for internal DNS queries. Docker assigns a DNS server for internal networks, which you can find by inspecting the Docker network:
docker network inspect my-network
Use this IP in your Nginx configuration:
resolver <docker-dns-ip>;
3. Resolve systemD Resolver Conflicts
Since you’ve disabled the systemD resolver, ensure it’s not affecting Docker’s DNS service. Check if Docker’s internal DNS is operational and not overridden.
4. Review NginXManager Settings
Ensure NginXManager isn’t inadvertently altering DNS settings. It should be configured to work harmoniously with Docker’s networking.
Testing and Verification
After making these changes, test by pinging containers by name from within the Nginx container. If set up correctly, this should now resolve correctly.