简体   繁体   中英

Windows Server Core Docker Containers networking problem

I have 2 containers created via docker compose with the following settings:

docker-compose.yml File:

version: "3.7"
services:
    web:
        image: img_web
        container_name: cont_web

    svcs:
        image: img_svcs
        container_name: cont_svcs
        depends_on:
            - web

Dockerfile for img_web:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
WORKDIR /inetpub/wwwroot

Dockerfile for img_svcs:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
WORKDIR /inetpub/wwwroot

After docker-compose up -d , and from cont_svcs container, I'm able to:

  1. Ping cont_web by IP

  2. Ping cont_web by hostname (container id: bf4001be1e84 autogenerated.)

BUT I CAN'T Ping the cont_web container by its alias (web)

I inspected both containers, I can see in the network sections the following:

"Networks": {
            "test_default": {
                "IPAMConfig": null,
                "Links": null,
                "Aliases": [
                    "bf4001be1e84",
                    "web"
                ],
...

Both containers are connected to the 'test_default' driver.

NB: Even I can't ping the web machine by its "web" alias name within the machine itself.

I would greatly appreciate your help and feedback.

Thanks Sam

Try adding an explicit NAT network to use for your deployment. To do this, add the following at the end of your docker-compose file-

networks:
  default:
    external:
      name: nat

Now, try pinging the services with their service name.

If that doesn't work, there might be a Security Firewall or Internet Security application is installed in your local machine which most probably is blocking the dockerd.exe DNS services. Try implementing some rules to allow the TCP and UDP ports regarding docker based services.

Also you can try this workaround to resolve the DNS correctly- https://github.com/docker/for-win/issues/1976#issuecomment-418151244

That's because Netbios resolution works for primary name. you can try to add 2nd Netbios name through registry: https://www.techrepublic.com/blog/the-enterprise-cloud/adding-multiple-netbios-names-for-windows-servers/

alternatively i'd recommend make a 2nd Cname record in DNS and doing the resolution with static names (might not be acceptable to you for your docker containers)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM