I'm new to Docker and really want to experience its features. Here I would like to run a simple Asp.net core web api in Docker (using docker run) instead of running it using IIS.
It's simple because it's exactly the default auto-gen ASP.NET core Web API project with only one controller named ValuesController. Normally when debugging with IISExpress, the following URI should respond an array of values:
http://localhost:[some_port]/api/values
Now I add Docker support for the project (using Windows container). After building the Docker image, it can be listed using docker images. Now I run the Docker image to host my web api like this:
docker run -t -rm -p 80:50633 hellodocker:dev
It runs OK and I can check that using docker ps. However to test if it's actually working I've tried typing the following address into a browser:
http://localhost/api/values
and it's not working, nothing displayed and it looked just like a non-existent site.
When I try the following command docker exec [container_id] netstat, it sometimes shows a record with status of TIME_WAIT and almost the time there is not any. Although I'm not sure if this relates to the outside listening.
Here is the Dockerfile's content:
FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 50633
EXPOSE 44322
FROM microsoft/dotnet:2.2-sdk-nanoserver-1803 AS build
WORKDIR /src
COPY HelloDocker/HelloDocker.csproj HelloDocker/
RUN dotnet restore HelloDocker/HelloDocker.csproj
COPY . .
WORKDIR /src/HelloDocker
RUN dotnet build HelloDocker.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish HelloDocker.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "HelloDocker.dll"]
I'm really stuck at this. A hello-world app may just print out a simple string but this hellodocker should be hosted in docker and serve any HTTP requests just like when we host it in IIS.
Update
After trying removing the built image and rebuilding another one instead, it looks like different after running with the same docker run command above:
Hosting environment: Production
Content root path: C:\app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
As before nothing displayed and the prompt root path becomes C:\app.
So this time it looks more obvious that it's listening for requests. However it's still not working.
50633?dockerfile, you can see the line EXPOSE 50633