0

I have created a sample ASP.Net Core Web Application and trying to run via Docker. (Windows 7 and Docker Toolbox Installation)

Here's my Docker file (Configured for Linux VM)

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:5000

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["SampleDockerWebApp.csproj", "./"]
RUN dotnet restore "./SampleDockerWebApp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "SampleDockerWebApp.csproj" -c Release -o /app

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

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

Build was successful and got the following output:

e:\Other Projects\SampleProjects\DockerSample\SampleDockerWebApp>docker build -t cog/aspnetcore .
Sending build context to Docker daemon  4.741MB
Step 1/16 : FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
 ---> ce06b36fcba4
Step 2/16 : WORKDIR /app
 ---> Using cache
 ---> 184385dc16fb
Step 3/16 : ENV ASPNETCORE_URLS=http://+:5000
 ---> Running in cc7cf2932649
Removing intermediate container cc7cf2932649
 ---> 33c2ffc6311d
Step 4/16 : FROM microsoft/dotnet:2.2-sdk AS build
 ---> a4974ac66bfc
Step 5/16 : WORKDIR /src
 ---> Using cache
 ---> 7f9a2990f973
Step 6/16 : COPY ["SampleDockerWebApp.csproj", "./"]
 ---> Using cache
 ---> 454d49d40a80
Step 7/16 : RUN dotnet restore "./SampleDockerWebApp.csproj"
 ---> Using cache
 ---> 004067a08191
Step 8/16 : COPY . .
 ---> Using cache
 ---> e592a6eaf72d
Step 9/16 : WORKDIR "/src/."
 ---> Using cache
 ---> 0429435802ea
Step 10/16 : RUN dotnet build "SampleDockerWebApp.csproj" -c Release -o /app
 ---> Using cache
 ---> be154237597e
Step 11/16 : FROM build AS publish
 ---> be154237597e
Step 12/16 : RUN dotnet publish "SampleDockerWebApp.csproj" -c Release -o /app
 ---> Using cache
 ---> 0d0e5b7d2fba
Step 13/16 : FROM base AS final
 ---> 33c2ffc6311d
Step 14/16 : WORKDIR /app

After this, I ran the Docker Run command to create a container

e:\Other Projects\SampleProjects\DockerSample\SampleDockerWebApp>docker run -d -p 8080:5000 cog/aspnetcore

Here, the container is created successfully and I am able to see the following log:

E:\Other Projects\SampleProjects\DockerSample\SampleDockerWebApp>docker logs -f
a67a1d48f6a0089c4a6e92c2b56a095203290b09c679db172fb2b955bcfd424a
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {77e3802b-efee-4a06-8daa-831a0e0ef771} may be persisted to storage in unencrypted form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:5000
Application started. Press Ctrl+C to shut down.

As per the log, container is ready and listening to http://[::]:5000. But, when I try to browse the website using http://localhost:5000 or http://localhost:8080 both the URLs are not working.

55SK55
  • 621
  • 2
  • 8
  • 23
  • Try to mention the host `"http://0.0.0.0:5000"` in `ENTRYPOINT` and check. Look @https://stackoverflow.com/questions/35731548/asp-net-on-docker-not-serving-web-app-to-browser – Sameer K May 09 '19 at 14:09
  • Tried ENTRYPOINT ["dotnet", "SampleDockerWebApp.dll", "--server.urls", "http://0.0.0.0:5000"] but not working – 55SK55 May 09 '19 at 14:13
  • 1
    maybe you should add EXPOSE 5000 to your Dockerfile – e.g78 May 09 '19 at 14:17
  • 1
    On Docker Toolbox you have to use the `docker-machine ip` address, usually 192.168.99.100, instead of `localhost`. – David Maze May 09 '19 at 18:23
  • What do you mean by `not working`? What error did you receive? I made a test with your dockerfile and command, it works correctly. – Edward May 10 '19 at 06:43
  • @TaoZhou I got the solution from David-Maze. I suppose to use docker-machine IP address instead of local-machine. It's working fine. – 55SK55 May 13 '19 at 05:19

0 Answers0