Introduction
This article aims to help you troubleshoot DNS connection issues in a Docker container running on Debian 12, with Pi-hole and unbound installed. The container is unable to access the internet using DNS, and we will cover the key concepts and steps required to resolve this issue.
Background
Docker is an open-source platform for developing, shipping, and running applications. It uses containerization technology to create isolated environments for applications and their dependencies. In this setup, we are using Debian 12 as the base operating system for our Docker container.
Pi-hole is an open-source network-wide ad and malware blocking solution. It acts as a DNS server, and its primary goal is to block known malicious and advertising domains. unbound is a validating, recursive, and caching DNS resolver. It is configured to work with Pi-hole and acts as the actual DNS server that resolves queries.
Symptoms
The Docker container is unable to access the internet using DNS. When running a command like "curl gitlab.my.domain" inside the container, it fails to connect and returns an error message. The container's network interface is not able to resolve the domain name, and the issue is most likely related to the DNS configuration within the container.
Steps to Resolve
Check Docker Networking
First, let's check the network connectivity of the Docker container. Run the following command in the terminal:
$ docker exec ping google.com
If the ping command fails, check the Docker network configuration. Ensure that the container is connected to the correct network and that the network has internet access.
Check Pi-hole Configuration
Next, let's check the Pi-hole configuration. Run the following command inside the Docker container:
$ su root
$ cat /etc/pihole/gravity.list
$ cat /etc/pihole/adlists.list
Check if the Pi-hole configuration files are present and contain the correct list of ad-blocking domains. If not, update the lists using the following command:
$ su root
$ pihole -g
Check unbound Configuration
Now, let's check the unbound configuration. Run the following command inside the Docker container:
$ su root
$ cat /etc/unbound/unbound.conf
Check if the unbound configuration file is present and correctly configured. Make sure the Pi-hole server IP address is listed as a forwarder in the unbound.conf file:
forward-zone:
name: ".";
forward-addr: ;
Restart Services
Restart the Pi-hole and unbound services using the following commands:
$ su root
$ systemctl restart pihole
$ systemctl restart unbound
Summary
In this article, we have covered the steps to troubleshoot DNS connection issues in a Docker container running on Debian 12, with Pi-hole and unbound installed. We have discussed the background of the problem, symptoms, and steps to resolve the issue. By following these steps, you should be able to resolve the DNS connection issue in your Docker container.