-1

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.

enter image description here

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Copy-pasted error reports are preferred to images of error reports as it can be [searched for and tested out](https://meta.stackoverflow.com/q/285551/12892553) and in addition [Users from certain countries can't view hosted images](https://meta.stackoverflow.com/q/407369/12892553) – Nimantha Jan 15 '22 at 04:35

2 Answers2

0

Please change your Dockerfile and add ASPNETCORE_URLS as shown below

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS base
ENV ASPNETCORE_URLS=http://+:80 
WORKDIR /app
COPY Published .
ENTRYPOINT ["dotnet", "DemoApi.dll"] 

Reference: https://stackoverflow.com/a/59662573/2777988

Rakesh Gupta
  • 3,507
  • 3
  • 18
  • 24
0

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 any COMMAND 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

docker run -p 8600:5000 demoapi:v1

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 be http://localhost:8600

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35