Erratic, intermittent issues with container hostnames and DNS name resolution

Hi Folks,

Have been using docker and docker-compose inside Virtualbox VMs running Alpine 3.13 guestOS, on a Windows 10 Professional host.

  • Docker version 20.10.3, build 48d30b5b32e99c932b4ea3edca74353feddd83ff
  • docker-compose version 1.27.4, build unknown

I use 2 docker-compose .yml files to bring up, 2 set of containers. First .yml file brings up Telgraf, InfluxDB, Grafana containers based on images from DockerHub. The second .yml brings up a POJO-server (Java) with application and another 3 tester/simulators.They all share a dedicated network ‘mynet’ (using bridged driver). The above setup seems to work perfectly at times. For example:

  • Sometimes , containers don’t seem to get hostname assigned (i.e. the mnemonic container-id is set as hostname, as is default) while at other times specific hostname is indeed assigned.

  • Then, for few containers (not all), the inter-container DNS/name resolution doesn’t seem to work, but at the same time few other containers have perfectly working inter-container DNS/name resolution. When inter-container DNS resolution does-not, if I log into the container runtime using ‘docker exec -it bash’, and try to do 'ping ', I get the following error:
    ping: somehostname: Temporary failure in name resolution

  • Sometimes, some containers (not all) require the "service: > hostname: " declaration in the docker-compose .yml file to get specific hostname assigned to the container, but for other containers at other times, that declaration is not needed, and only the “container_name” declaration is enough (in .yml file) to have specific hostname for that container !!

Wondering if anyone can help figure out why is the behaviour erratic ? What can I do to fix it ?

Thanks in anticipation.