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
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?
