不能将中间docker容器文件复制到主机

我有一个Dockerfile,它做dotnet发布和dll被复制到中间docker容器。 我想复制在我的本地系统(主机)的容器中生成的DLL。

我相信我们可以使用“cp”命令来做到这一点,但我无法find一个解决scheme,让中间容器Id使用“cp”命令。

语法:docker cp CONTAINER:Container_Path Host_Path。

请为我提出任何其他更好的解决scheme。

Dockerfile:

FROM microsoft/aspnetcore-build:1.1.4 as builder COPY . /Code RUN dotnet restore /Code/MyProj.csproj RUN dotnet publish -c Release /Code/MyProj.csproj RUN cp CONTAINER: /Code/bin/Release/netcoreapp1.1/publish /binaries 

谢谢。

这个答案在Dockerfile之外。 首先你的Dockerfile将不得不有一个卷。 [VOLUME] / my / path / in / container

要使文件进出卷,请尝试使用tar -cvf和tar -xvf在容器和主机之间放置和获取文件。

把主机的newfiles.tar中的文件放到/ var / lib / neo4j / conf mount的容器中。

 docker run --rm \ -v my-volume-data:/my/path/in/container -v $(pwd):/newfiles ubuntu bash -c \ "cd /my/path/in/container && tar -xf /newfiles/newfiles.tar" 

将文件从/ my / path / in / container装载到主机oldfiles.tar的容器中。

 docker run --rm \ -v my-volume-data:/my/path/in/container -v $(pwd):/newfiles ubuntu bash -c \ "cd /my/path/in/container && tar -cf /newfiles/origfiles.tar" 

如果您的容器有一个uid为1000的用户,那么--user 1000:1000是可选的。