I installed some containers that needed to talk with the rest of the servers outside of the container and found it weird they couldn't resolve at all over DNS.
Turns out that there are few things you need to configure for it to work properly.
- Make sure you have DNS resolving configured on the host and pointing to your DNS servers
- You can check the resolver file on a container by using this command: sudo docker exec <container> cat /etc/resolv.conf
- To test if the container can resolve a DNS name use this command: sudo docker exec <container> ping <DNSname>
- Check the assigned docker network for the container, if it's in a different network it might not be able to resolve using DNS
- To check how many networks there are use this command: sudo docker network ls
- To find out which network the container is using, use this command: sudo docker inspect <container> -f "{{json .Networksettings.Networks }}"
You should see the name of the network in the results - To remove the network from the container use this command: sudo docker network disconnect <networkname> <container>
- To add a network to the container use this command: sudo docker network connect <networkname> <container>
You might need to restart the container before the DNS works