reverse-proxy icon indicating copy to clipboard operation
reverse-proxy copied to clipboard

.NET 9 and latest DOcker Desktop on Windows 11 Pro -> Unable to call destination container by name(Aliases Network Name in Docker) anymore, have to use 'host.docker.internal:PortNumber'

Open pastrasigns opened this issue 1 year ago • 10 comments

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Deploy latest .NET 9 APIs with YARP setting calling the container by name within the URL with portnumbers, the below doesn't work anymore:

        "Clusters": {
            "addresses-cluster": {
                "Destinations": {
                    "addresses-cluster/destination1": {
                        "Address": "http://address.api:5563"
                    }
                }
            },
            "test-cluster": {
                "Destinations": {
                    "test-cluster/destination1": {
                        "Address": "http://testapi:5006"
                    }
                }
            }
        }

This works with the latest .NET 9 with latest Docker Desktop:

        "Clusters": {
            "addresses-cluster": {
                "Destinations": {
                    "addresses-cluster/destination1": {
                        "Address": "http://host.docker.internal:5563"
                    }
                }
            },
            "test-cluster": {
                "Destinations": {
                    "test-cluster/destination1": {
                        "Address": "http://host.docker.internal:5006"
                    }
                }
            }
        }

Got Exceptions? Include both the message and the stack trace -->

Further technical details

  • .NET 9 latest .Net core LINUX on Docker Desktop running WSL2.
  • Windows 11 Pro.
  • Latest Docker Desktop latest
  • VS2022 Community latest.

Image

pastrasigns avatar Jan 23 '25 23:01 pastrasigns

Can you share how you have docker configured (yarp & other services)?

YARP doesn't do anything special re: docker. If the host is reachable it'll work, so if it's not it's likely an issue in your docker setup.

MihaZupan avatar Jan 30 '25 15:01 MihaZupan

@MihaZupan Running latest Docker desktop and .NET 9:

docker-compose.yml file below:

`services:

identity.customer.api: image: ${DOCKER_REGISTRY-}identitycustomerapi container_name: identity.customer.api build: context: . dockerfile: src/Identity.Customer.API/Dockerfile ports: - 5553:5553 - 5554:5554 networks: - proxybackend

addresses.api: image: ${DOCKER_REGISTRY-}addressesapi build: context: . dockerfile: src/Addresses.API/Dockerfile ports: - 5563:5563 - 5564:5564 networks: - proxybackend

networks: proxybackend: name: proxybackend driver: bridge`

docker-compsose.override.yml

`services: identity.customer.api: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_HTTP_PORTS=5553 - ASPNETCORE_HTTPS_PORTS=5554 ports: - "5553" - "5554" volumes: - ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro - ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro

addresses.api: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_HTTP_PORTS=5563 - ASPNETCORE_HTTPS_PORTS=5564 ports: - "5563" - "5564" volumes: - ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro - ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro`

Dockerfile for my API Identity Yarp service:

FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base USER app WORKDIR /app EXPOSE 5553 EXPOSE 5554

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["Identity.Customer.API/Identity.Customer.API.csproj", "Identity.Customer.API/"] RUN dotnet restore "./Identity.Customer.API/Identity.Customer.API.csproj" COPY . . WORKDIR "/src/Identity.Customer.API" RUN dotnet build "./Identity.Customer.API.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./Identity.Customer.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Identity.Customer.API.dll"]

Docker desktop (latest):

Image

pastrasigns avatar Jan 30 '25 15:01 pastrasigns

Could you just be looking at a typo? address.api:5563 => addresses.api:5563

MihaZupan avatar Jan 30 '25 17:01 MihaZupan

Could you just be looking at a typo? address.api:5563 => addresses.api:5563

@MihaZupan Thanks for noticing, but I recently updated everything to 'addresses.api'.

Image

Image

This is currently working fine:

Image

This is not:

Image

The Error returned in postman for above Address destination cluster:

Error: getaddrinfo ENOTFOUND addresses.api

Image

  • I also reinstalled docker on my local machine, very weird.

pastrasigns avatar Jan 30 '25 18:01 pastrasigns

Just a guess, have you tried not including dots in your service name? E.g. name the service addresses-api instead?

MihaZupan avatar Jan 30 '25 18:01 MihaZupan

  1. Milan .NET youtube start uses dots with .NET 8 and it works: https://youtu.be/UidT7YYu97s?si=SMKQ2rsaDXE9H9bp&t=615

  2. I have tried using dashes 'Error: getaddrinfo ENOTFOUND addresses-api' same error in postman and within insomnia app (like postman).

pastrasigns avatar Jan 30 '25 18:01 pastrasigns

Can anyone else test this bug? Should we make it a new Yarp Bug with latest .NET 9 ?

pastrasigns avatar Feb 03 '25 22:02 pastrasigns

I'm not familiar with the video. When using YARP and/or Postman, are you using it from inside Docker? It's expected that DNS resolution will differ from outside the network such that services can't be resolved.  

Should we make it a new Yarp Bug with latest .NET 9 ?

I don't understand the question?

MihaZupan avatar Feb 03 '25 22:02 MihaZupan

@MihaZupan Is there a good working YARP .NET 9 Example which runs with docker-compose on Docker desktop? url?

pastrasigns avatar Feb 05 '25 14:02 pastrasigns

This was resolved in in here:

https://github.com/dotnet/yarp/issues/2735

Done. Not a bug.

Thanks for assistance.

pastrasigns avatar Feb 07 '25 18:02 pastrasigns