What I have is a simple .net core api and my docker file looks like this.
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS base
WORKDIR /app
COPY Published .
ENTRYPOINT ["dotnet", "DemoApi.dll"]
I am starting the container with the following command
docker run demoapi:v1 -p 8600:80
and I get a message as below.
When I try to access the API wiht the URL http://:8600 , I get a message site cant be reached. I even tried with port 5000, 80 but nothing works.
What is that I am missing here.
2
Answers
Please change your Dockerfile and add ASPNETCORE_URLS as shown below
Reference: https://stackoverflow.com/a/59662573/2777988
Parameters for Docker go before the image name in the
docker run
command. Anything after the image name becomes a command for the container and overrides anyCOMMAND
that may be set in the image. The port-mapping parameters are Docker parameters, so they need to go before the image name.Also, you use the SDK image to run your application. That’s fine, but that image doesn’t set ASPNETCORE_URLS to http://+:80, so your app listens on port 5000, so you need to map that, instead of port 80
If you used the ‘proper’ runtime image,
mcr.microsoft.com/dotnet/aspnet:3.1
, that would set ASPNETCORE_URLS. Then your app would listen on port 80 and you should map that.You say you use
http://:8600
to access the API. That should behttp://localhost:8600