For existing ASP.NET Core MVC project on Windows build server, how to target a Docker container without disturbing earlier build pipeline stages?
Fixed it by two changes:
1) Change the DLL name in the Dockerfile to be case sensitive. The app runs inside a container whose OS is case sensitive Linux.
2) Change the port number mapping in the "docker run" commmand
Troubleshooting steps:
1. In a Visual Studio 2019 command prompt window, go to the publish directory
2. Run the web site "dotnet AspNetMvcCoreTestApp2.dll". This command is the same one run inside the Docker container.
It produces this output. Notice the port number 5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
3. Open a browser and go to http://localhost:5000/ and the start page of the site is displayed
4. Change the Dockerfile to list the correct DLL name including case sensitive letters. Also verify thta the .NET core version in the Dockerfile is the same as the one in the Visual Stuido 2019 explorer.
# Build runtime imageFROM mcr.microsoft.com/dotnet/core/aspnet:3.0WORKDIR /appCOPY . .ENTRYPOINT ["dotnet", "AspNetCoreTestProject2.dll"]EXPOSE 80
- Remove any images for the container in Docker if needed
Run "docker image ls" and make note of the IMAGE_ID of the existing image if it exists
Run "docker rmi IMAGE_ID" to remove the image - Build the docker image "docker build -t aspnetcoretestproject2 ."
- Enter "docker image ls" and make note of the IMAGE_ID value for aspnetcoretestproject2
REPOSITORY TAG IMAGE ID CREATED SIZE aspnetcoretestproject2 latest 58c92979be61 3 minutes ago 212MB mcr.microsoft.com/dotnet/core/sdk 3.0-buster 4422e7fb740c 3 weeks ago 689MB
- Run the docker image mapping local host port 5000 to port 80 inside the Docker container
"docker run -d -p 5000:80 58c92979be61" - Verify the docker container is running by "docker container ls"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c52ab21b9c25 58c92979be61 "dotnet AspNetCoreTe…" 4 seconds ago Up 2 seconds 0.0.0.0:5000->80/tcp magical_leavitt e4152fcb2233 f80194ae2e0c "ping 8.8.8.8" 3 minutes ago Up 3 minutes k8s_testpod_demo_default_dd2702f7-eeac-11e9-a181-00155dde9201_2
- Open web browser and enter http://localhost:5000 in the URL bar. This should show the start page of the ASP.NET web site
Put the command "EXPOSE" before the command "ENTRYPOINT".Also, you forgot to add environment variables for ASP Core runtime.
Fixed Dockerfile:
# Build runtime imageFROM mcr.microsoft.com/dotnet/core/aspnet:3.0WORKDIR /appEXPOSE 80 # container listens on the port at runtimeENV ASPNETCORE_URLS=http://+:80 # bind port 80 for httpCOPY . .ENTRYPOINT ["dotnet", "AspNetCoreTestProject2.dll"]
Read more about the ASPNETCORE_URLS here