无法将中间docker容器文件复制到主机

问题描述 投票:0回答:1

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

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

语法:docker cp CONTAINER:Container_Path Host_Path。

请为我建议任何其他更好的解决方案。

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

谢谢。

asp.net docker asp.net-core-mvc dockerfile
1个回答
0
投票

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

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

将文件从主机的newfiles.tar放入pwd到/ 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 mount中的容器中获取到主机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是可选的。

© www.soinside.com 2019 - 2024. All rights reserved.