将文件从Docker容器复制到主机

将文件从Docker容器复制到主机

问题描述:

我正在考虑使用Docker在持续集成(CI)服务器上构建我的依赖项,这样我就不必在代理程序本身上安装所有运行时和库。

I'm thinking of using Docker to build my dependencies on a Continuous Integration (CI) server, so that I don't have to install all the runtimes and libraries on the agents themselves.

要实现这一点,我需要将容器内部构建的构建工件复制回主机。

To achieve this I would need to copy the build artifacts that are built inside the container back into the host. Is that possible?

要将文件从容器复制到主机,可以使用命令

In order to copy a file from a container to the host, you can use the command

docker cp <containerId>:/file/path/within/container /host/path/target

下面是一个示例:

$ sudo docker cp goofy_roentgen:/out_read.jpg .

这里 goofy_roentgen 是我从以下命令中获得的容器名称:

Here goofy_roentgen is the container name I got from the following command:

$ sudo docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                            NAMES
1b4ad9311e93        bamos/openface      "/bin/bash"         33 minutes ago      Up 33 minutes       0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp   goofy_roentgen

您还可以使用容器ID (的一部分)。以下命令等效于第一个

You can also use (part of) the Container ID. The following command is equivalent to the first

$ sudo docker cp 1b4a:/out_read.jpg .