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

时间:2022-05-21 15:47:29

I have a Dockerfile, it does dotnet publish and the dll's are copied to intermediate docker container. I would like to copy the dll's which are generated in container to my local system (Host) as well.

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

I believe we can use "cp" command to do that, but I am not able to find a solution to get the intermediate container Id to use the "cp" command.

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

syntax: docker cp CONTAINER:Container_Path Host_Path.

语法:docker cp CONTAINER:Container_Path Host_Path。

Please suggest me any other better solution for this scenario.

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

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

Thanks.

1 个解决方案

#1


0  

This answer is outside of the Dockerfile. first your Dockerfile would have to have a volume. [VOLUME] /my/path/in/container

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

To get files into and out of a volume, try using tar -cvf and tar -xvf to put and get files between a container and a host.

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

To put files from host's newfiles.tar in pwd to a container at /var/lib/neo4j/conf mount.

将文件从主机的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"

To get files from into a container at /my/path/in/container mount to a host oldfiles.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"

The --user 1000:1000 is optional if your container has a user with uid of 1000.

如果容器的uid为1000,则--user 1000:1000是可选的。

#1


0  

This answer is outside of the Dockerfile. first your Dockerfile would have to have a volume. [VOLUME] /my/path/in/container

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

To get files into and out of a volume, try using tar -cvf and tar -xvf to put and get files between a container and a host.

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

To put files from host's newfiles.tar in pwd to a container at /var/lib/neo4j/conf mount.

将文件从主机的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"

To get files from into a container at /my/path/in/container mount to a host oldfiles.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"

The --user 1000:1000 is optional if your container has a user with uid of 1000.

如果容器的uid为1000,则--user 1000:1000是可选的。