1

I am trying to run an asp.net core web application from Dockers container without using Visual Studio but it is not running. I am following the steps listed in this tutorial on Microsoft site.

I have successfully done everything which are:

  1. Creating Image.
  2. Creating and running container with the ASP.NET Core Application.

The Dockers desktop shows that the image and container are both running.

The image (testn) screenshot:

enter image description here

The container (myapp) screenshot:

enter image description here

Now when I open the app url in the browser which is "http://localhost:8080/. I get "This page isn’t working" message. See below image:

enter image description here

My Dockerfile code is:

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build-env

WORKDIR /app

# Copy csproj and restore as distinct layers

COPY *.csproj ./

RUN dotnet restore

# Copy everything else and build

COPY . ./

RUN dotnet publish -c Release -o out

# Build runtime image

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build

WORKDIR /app

COPY --from=build-env /app/out .

ENTRYPOINT ["dotnet", "Testn.dll"]

I am using Lixus container in Dockers Desktop. My laptop OS is Windows 10 Home.

What I am missing?

yogihosting
  • 5,494
  • 8
  • 47
  • 80

1 Answers1

0

Your 8080 port is just exposed, but not published dear. You should publish your port when you are going to run the container from image like this: docker run -d -p 8080:8080 testn:latest

Amir
  • 1,214
  • 7
  • 10
  • You can see the difference between exposing and publishing here: https://stackoverflow.com/questions/22111060/what-is-the-difference-between-expose-and-publish-in-docker#:~:text=Exposing%20ports%20is%20a%20way,on%20the%20container's%20network%20interface. – Amir Jan 28 '21 at 16:09
  • Your command is not running, it has systax error. The command I ran is `docker run -d -p 8080:80 --name myapp testn`. It ran the container successfully but the url is not opening on the browser. I have followed this step which is provided in the offical docs itsef - https://devblogs.microsoft.com/premier-developer/running-a-net-core-web-application-in-docker-container-using-docker-desktop-for-windows/ – yogihosting Jan 28 '21 at 16:14
  • Thanks, dude, I fixed the syntax :D. What port is your application listening to? if your application is listening on PORT P1 and you want to visit the browser on port P2 you should do something like this: docker run -d -p P2:P1 --name myapp testn:latest – Amir Jan 28 '21 at 16:20
  • Port should be 8080 based on the url localhost:8080 – yogihosting Jan 28 '21 at 16:24
  • I just figured it out. The 3.1 image is working but 5.0 image is not working. – yogihosting Jan 28 '21 at 18:54