So this is my setup:
- .NET Minimal APIs running in a Docker Container
- Keycloak running in a Docker Container
In the development environment of my minimal-Api I can make a Http Request against the Keycloack Container to get an AccessToken
After running my api in a Docker Container the request isn’t working anymore.
After the making the request I get the Error:
"Address not available (localhost:8080)"
This is how I do the Request in the Api:
this is the Dockerfile to build the Image for the minimal Api:
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build-env
WORKDIR /app
COPY . ./
RUN dotnet restore
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "projectName.dll"]
2
Answers
So this kinda helped me. Yes its not the localhost. Better solution is to look into the Ip-Address which is given to the container by docker. You can do it by using: docker inspect <container-name/id> look for the IP Address
localhost
:When you will run your app in the docker container
localhost
will mean the container itself, not the host machine, and your container obviously does not have docker installed. If you are running on Windows then you can usehost.docker.internal
to reach outside the container i.e.host.docker.internal:8080
(maybe it is supported on other systems but can’t verify this now). If this does work you can try getting acquainted with docker networking (and this) and leveraging it.Notes and see also: