Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is my source code on docker container

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

enter image description here

Where does docker keep the source code?

like image 618
OpenStack Avatar asked Apr 11 '26 09:04

OpenStack


1 Answers

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.

like image 168
Max Avatar answered Apr 12 '26 22:04

Max