3

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

Sameh
  • 934
  • 1
  • 14
  • 40

2 Answers2

1

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

Shahed Mehbub
  • 551
  • 1
  • 3
  • 7
1

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)

Shahid Roofi Khan
  • 957
  • 1
  • 8
  • 19
  • Thank you very much for your answers, do you mean set the Netbios name of the CONTAINER and "OptionalName" is the host address? – Sameh Apr 07 '20 at 09:52
  • yes Sameh that's what i meant. its Netbios resolution in action when you just use hostname to ping. It's where you need to find resolution – Shahid Roofi Khan Apr 07 '20 at 13:37