Home > Enterprise >  Docker how to copy dotnet published folder to local machine
Docker how to copy dotnet published folder to local machine

Time:03-24

I have a dockerfile in which I build a console application. After running the publish commmand within the dockerfile I can see the output folder using RUN ls-la. My questions how can I export or extract the output folder (app/out in this case) that was built to view the files on my local machine?

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
WORKDIR /app
COPY . .

RUN dotnet --info
RUN dotnet restore ./MyProject.csproj
RUN ls -la
RUN dotnet publish ./MyProject.csproj -c Release -o out

RUN ls -la


# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "MyProject.dll"]

CodePudding user response:

You can run the container and copy the files to a mounted directory. On Linux, you can mount the current directory and copy like this (replace <image name> with the name of your image)

docker run --rm -v $(pwd):/dest --entrypoint bash <image name> -c "cp * /dest/"

On Windows, you can do this instead from a command prompt (it doesn't work in Powershell)

docker run --rm -v            
  • Related