'Docker how to copy dotnet published folder to local machine
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"]
Solution 1:[1]
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 %cd%:/dest --entrypoint bash <image name> -c "cp * /dest/"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hans Kilian |