CodexBloom - Programming Q&A Platform

Debian 11 - NetworkManager scenarios to apply DNS changes for Docker containers

👀 Views: 40 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-06
Debian Docker NetworkManager DNS bash

I've been struggling with this for a few days now and could really use some help. I'm working with a frustrating scenario with NetworkManager on Debian 11, where changes to DNS settings are not being applied correctly for Docker containers. I've set up a custom DNS server in my NetworkManager configuration file, but it seems that Docker containers are not using these DNS settings. Instead, they default to the DNS servers specified in `/etc/resolv.conf`. I've tried modifying the `/etc/NetworkManager/NetworkManager.conf` file to include the following: ```ini [main] dns=systemd-resolved ``` Then I restarted the NetworkManager with: ```bash sudo systemctl restart NetworkManager ``` Next, I updated the Docker daemon settings in `/etc/docker/daemon.json` to specify the DNS as follows: ```json { "dns": ["192.168.1.1"] } ``` After making these changes, I restarted the Docker service: ```bash sudo systemctl restart docker ``` However, when I launch a container and check the DNS settings with: ```bash docker run --rm busybox cat /etc/resolv.conf ``` I still see the default DNS settings instead of my custom DNS server. I even tried to remove the existing containers and images to ensure there were no residual settings affecting this, but the question continues. Is there a way to ensure that Docker containers respect the DNS settings configured in NetworkManager? Any insights on this would be much appreciated! What's the best practice here?