2

Working with Docker Windows Containers I want to go beyond only one Docker container running a App. As described in the Microsoft docs under the headline "Docker Compose and Service Discovery":

Built in to Docker is Service Discovery, which handles service registration and name to IP (DNS) mapping for containers and services; with service discovery, it is possible for all container endpoints to discover each other by name (either container name, or service name).

And because docker-compose lets you define services in it´s yaml files, these should be discoverable (e.g. pingable) by there names (be sure to remind the difference between services and containers in docker-compose). This blog post by Microsoft provides a complete example with the service web and db including full source with the needed docker-compose.yml in the GitHub repo.

My problem is: the Docker windows containers do "find" each other only sometimes, and sometimes not at all. I checked them with docker inspect <container-id> and the alias db and web are present there. But when I powershell into one container (e.g. into one web container via docker exec -it myapps_web_1 powershell) and try to do a ping db this only works only occasionally.

And let me be clear here (because IMHO the docs are not): This problem is the same for non docker-compose scenarios. Building an example app without compose, the problem also appears without docker-compose services, but just plain old container names!

Any ideas on that strange behavior? For me this scenario gets worse with more apps coming into play. For more details, just have a look into https://github.com/jonashackt/spring-cloud-netflix-docker, where I have an example project with Spring Boot & Spring Cloud Eureka/Zuul and 4 docker-compose services, where the weatherbackend and weatherbackend-second are easily scalable - e.g. via docker compose scale weatherbackend=3.

My Windows Vagrant box is build via packer.io and is based on the latest Windows Server 2016 Evalutation ISO. The necessary Windows Features and Docker/docker-compose installation is done with Ansible.

Having no fix for this problem, Docker Windows Containers become mostly unusable for us at the customer.

Community
  • 1
  • 1
jonashackt
  • 12,022
  • 5
  • 67
  • 124

2 Answers2

2

After a week or two trying to solve this problem, I finally found the solution. Beginning with the read of this docker/for-win/issues/500, I found a link to this multicontainer example application source where one of the authors documented the solution as a sideline, naming it:

Temporary workaround for Windows DNS client weirdness

Putting the following into your Dockerfile(s) will fix the DNS problems:

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN set-itemproperty -path 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters' -Name ServerPriorityTimeLimit -Value 0 -Type DWord

(to learn how the execution of Powershell commands inside Dockerfiles work, have a look into the Dockerfile reference)

The problem is also discussed here and the solution will hopefully find it´s way into a official Docker image (or at least into the docs).

jonashackt
  • 12,022
  • 5
  • 67
  • 124
  • This does not solve the problem for me. I'm running the latest windows server container that already has that registry value set and I still find that dns resolves to the wrong ip after a change. Is there any other solutions? – Mike Norgate Jun 15 '17 at 19:56
  • Could you provide some more detail about your setup? Do you want to use Docker Compose? Whats the output of a 'docker inspect containerId'? I have a done a complete example for my blog post https://blog.codecentric.de/en/2017/05/ansible-docker-windows-containers-scaling-spring-cloud-netflix-docker-compose/ here: https://github.com/jonashackt/ansible-windows-docker-springboot - maybe that one helps as well or to setup an example project to show your error?! – jonashackt Jun 16 '17 at 14:01
  • This solved the issue on my home PC (Win 10) but my work Laptop does not resolve services by their alias at all. I can get by instanceID. I'm guessing is down to how my laptop is configured. Anyone got any ideas where to start looking as the issue is likely my PC rather than docker. – Andrew Newland Oct 20 '17 at 12:33
  • Depending on something that is configured in a not 100% comprehensible way (e.g. through other people like sysadmins in your company) is usually causing a lot of lost time to find errors. I like the idea of using a virtualization layer with Vagrant and have a Windows 10 / Server 2016 setup with Packer, ideally destroyable and 100% automatically replaceable w/ the help of a provisioning tool like Ansible. If you want to go that way, I blogged about it, incl. a howto here https://blog.codecentric.de/en/2017/04/ansible-docker-windows-containers-spring-boot/ (no need for SpringBoot for that setup) – jonashackt Oct 20 '17 at 12:50
1

I have found out that I needed to open TCP in port 1888 to make the DNS work immediately. Without this port open, I had to connect to the container (windows in my case) and execute in PowerShell Clear-DnsClientCache each time the DNS changed (also during first swarm setup).