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.

4

2 回答 2

2

在尝试解决这个问题一两个星期后,我终于找到了解决方案。从阅读此docker/for-win/issues/500开始,我发现了一个指向此多容器示例应用程序源的链接,其中一位作者将解决方案记录为副业,并将其命名为:

Windows DNS 客户端异常的临时解决方法

将以下内容放入 Dockerfile(s) 将修复 DNS 问题:

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

(要了解如何在 Dockerfiles 中执行 Powershell 命令,请查看Dockerfile 参考

这里也讨论了这个问题,并且该解决方案有望在官方 Docker 镜像中找到(或至少在文档中)。

于 2017-03-27T08:23:27.257 回答
0

我发现我需要在端口1888中打开 TCP以使 DNS 立即工作。如果没有打开这个端口,我必须连接到容器(在我的例子中是 windows)并在每次 DNS 更改时(也在第一次集群设置期间)在 PowerShell Clear-DnsClientCache 中执行。

于 2019-01-08T15:03:01.810 回答