Search code examples
dockerdnsmanjaro

Manjaro: Resolve IP of host in Docker container via /etc/hosts


I have two systems:

  • Ubuntu
  • Manjaro

On both systems I installed Docker. Also I added an entry in the /etc/hosts file which looks like this

192.168.0.15 my-domain.com    # IP address of my host

When I now start a Docker container on the Ubuntu system, I can execute a ping or a curl on "my-domain.com" from inside the container and it works - the IP is resolved. When I do the same on the Manjaro system I get an error as "my-domain.com" cannot be resolved.

What could be the reason for this? Do I have to use systemd-resolved instead of the NetworkManager or something like this? Unfortunately, I'm not really familiar with the DNS topic. I tried multiple things - suggested by ChatGPT - but either this didn't worked or it got worse and the DNS was not able to resolve any URL (like google.com).

After reading a lot of threads/questions, I'm aware of the fact that I can also add the /etc/hosts file via volume into the container and also that I can define hosts via the docker run command. This allows me to resolve the IP, but I get later some problems in my OpenResty container, as there the "resolver", which is set to 127.0.0.11 doesn't work.

So in my understanding there is a general problem and difference regarding the DNS (usage).

Is there any possibility to get the same behavior like in the Ubuntu system? So without modifying my Docker stack. I don't understand why it behaves differently in Manjaro than in Ubuntu.


Solution

  • I found the solution for my scenario in the meantime.

    I use avahi, systemd-resolved and systemd-networkd. Additionally I deactived dnsmasq, as this has a conflict with systemd-resolved (I think).

    sudo systemctl enable --now avahi-daemon
    sudo systemctl enable --now systemd-resolved
    
    sudo systemctl stop dnsmasq
    sudo systemctl disable dnsmasq
    
    sudo systemctl enable --now systemd-networkd
    
    sudo mv /etc/resolv.conf /etc/resolv.conf.bak
    sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
    

    With this it behaves in the same way as in Ubuntu.