I used following docker script to build and run my ASP.NET Web API project on .net 4.6.1 framework.
FROM microsoft/dotnet-framework:4.7.2-sdk AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY TestWebAPI/*.csproj ./TestWebAPI/
COPY TestWebAPI/*.config ./TestWebAPI/
RUN nuget restore
# copy everything else and build app
COPY TestWebAPI/. ./TestWebAPI/
WORKDIR /app/TestWebAPI
RUN msbuild /p:Configuration=Release
FROM microsoft/aspnet:4.7.2 AS runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app/TestWebAPI/. ./
In the first step I am setting app folder as my working directory. But after creating container, I do not see any folder name app on my C:
--To create Image
docker image build --tag testwebapi --file .\Dockerfile .
--To run container
docker container run --detach --publish 80 testwebapi
--To see containers content
docker exec -i -t a1da40af6b3c powershell

Where does docker keep the source code?
You'll find your files in c:\inetpub\wwwroot.
Note that your Dockerfile has two FROM lines:
FROM microsoft/dotnet-framework:4.7.2-sdk AS build
...
FROM microsoft/aspnet:4.7.2 AS runtime
This is using a relatively new Docker feature called multi-stage builds. Basically, only the instructions from the second (and last) stage determine what's copied into the actual image:
WORKDIR /inetpub/wwwroot
COPY --from=build /app/TestWebAPI/. ./
Note that --from=build references the output of first stage - think of it as a temporary image. /inetpub/wwwroot is the WORKDIR of the second stage, so that's where you'll find the files from the final COPY step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With