2

I am trying to run an ASP.net core API in a Docker container. Running from Visual Studio works perfectly fine, but I cant access the API when I run it using the following powershell command:

docker run --name test6 --rm -it -p 9001:80 webapplication6:dev

It just return:

root@874b63595efc:/app#

I expect that it will show me that it has started listening to the given port. I tried to use an existing repo from Docker Hub to do a test:

docker run --name aspnetcore_sample --rm -it -p 8000:80 mcr.microsoft.com/dotnet/core/samples:aspnetapp

And it successfully returned the following:

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /app

It is accessible in my localhost. Going back to my test API project, I have the following text in my Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["WebApplication6.csproj", ""]
RUN dotnet restore "./WebApplication6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApplication6.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication6.dll"]

This was automatically added by Visual Studio.

Here is the output being returned by docker ps

docker ps result

The command value for my test application is "bash". Do I need to configure anything else for me to run the API container using Powershell alone and without using Visual Studio?

1 Answer 1

1

Seems like docker engine is ignoring the entrypoint directive in your Dockerfile, as you can see the command is null in your running container.

You can probably work around this issue by specifying a CMD directive in your Dockerfile. Try adding this line to the bottom of your Dockerfile and see if it helps:

CMD ["dotnet", "WebApplication6.dll"]

Also, make sure that your docker image is built with the current version of the Dockerfile, you can try using this command to verify that:

docker build -t webapplication6:dev .    
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.