So this is my setup:
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"]
In computer networking, localhost is a hostname that refers to the current computer used to access it. The name localhost is reserved for loopback purposes.
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 use host.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: