Docker inter-container hostname resolution not working

Published Updated 6 years ago

Issue: Container hostnames won’t get resolved to IP addresses within the default docker network.

This is more of a hint than a fix or workaround for an issue.

When playing around with Docker I’ve noticed hostnames of containers could not be resolved by other containers. So when setting up a Nextcloud instance I was forced to use the IP address of the database container, as the hostname just would not work. After some time I stumbled across the solution: When using the default docker network on container runs hostnames will not be resolved. Switching to a docker-compose command (or just running containers with a custom docker network) fixes this issue and hostnames can be resolved again. The documentation is unfortunately not very clear about this, but this seems to be a persistent issue, as I was able to reproduce this on my physical Debian machine as well as on a virtual Digitalocean host.

The docker version I have tested this issue on is 19.03.2

Comments

Comments are hosted on comments.itobey.dev. Loading them sets cookies and shares your IP address with that service.