skip to Main Content

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.

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search