When you create a new docker image that is part of a container composition that you want to run on one and the same host, you can run into the issue that the independent containers are not able to reach each other via DNS resolving.
So lets assume you have the following compose file where you want the web tier to be able to reach the database tier given the following compose file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
version: "2.1" services: web: build: ./web expose: - "80" depends_on: - db tty: true db: build: ./db expose: - "1433" environment: - "ACCEPT_EULA='Y'" tty: true networks: default: external: name: "nat" |
Based on this compose file the web tier should be able to resolve the database by the network name db and the db should be able to resolve the web tier by the name web.
Unfortunately at the moment there is a bug that should be fixed soon. the work around this at the moment is as follows:
in the docker files where you build your containers, you need to add the following statement:
1 2 |
#FIX DNS issues currently in Windows Containers RUN powershell set-itemproperty -path 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters' -Name ServerPriorityTimeLimit -Value 0 -Type DWord |
You need to add this line to each container that needs to reach out on the network and find the other container when using the NAT network.
So in case of my example this needs to be added to the Docker file of the web application, since it will go out and try to reach the database.
Hopefully this will be fixed soon, but in the meanwhile this can help you make things work.
Awesome, thank you so much! I’ve been puzzled for the whole day why my containers cannot connect to each other. First they were working, but suddenly everything stopped. You can imagine my reaction since I just had set up the environment in Azure and then this happened.
Also it might be worth mentioning that I got confirmation from MS that the fix should be included in April’s monthly updates.