Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

docker - 将文件从Docker容器复制到主机(Copying files from Docker container to host)

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.

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

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

(为此,我需要将容器内部构建的构建工件复制回主机。)

Is that possible?

(那可能吗?)

  ask by user2668128 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Here's an example:

(这是一个例子:)

$ sudo docker cp goofy_roentgen:/out_read.jpg .

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

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

$ 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

You can also use (part of) the Container ID .

(您还可以使用(部分) 容器ID 。)

The following command is equivalent to the first

(以下命令等效于第一个)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...