0

I have a .Net 3.1 API running as a Docker container (WSL2+ Linux Containers) on Windows 10. I am unable to access the API on any other ports except 5000 :

When i run the container as

docker run -d -p 8060:7110 golide/payapi:0.1.0

and try a GET in Postman to http://localhost:7110/weatherforecast I get "Unable to Connect" exception. But when i run the container as

docker run -d -p 5000:5000 golide/payapi:0.1.0

and try a GET in Postman to http://localhost:5000/weatherforecast I get the API response.

What am I missing regarding how Kestrel port binding works ?

My Dockerfile looks as follows :

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /app
ENV ASPNETCORE_URLS http://+:5000
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "PaymentsAPI.dll"]

What additional configuration should I do (if any) in order to access the API on any other port ?

1 Answer 1

2

For the port (-p) option of docker run, the format looks like <host-port>:<container-port>. Since you used a value of 8060:7110 and attempted to access localhost:7110 on the host, you're targeting the wrong port. You should be targeting 8060 from the host, or swap the position of the ports if that's what you need.

Then you'd also want to have ENV ASPNETCORE_URLS http://+:<container-port> set in your Dockerfile as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.