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.