Docker:将文件从 Docker 容器复制到主机 [英] Docker: Copying files from Docker container to host

查看:66
本文介绍了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 .

这篇关于Docker:将文件从 Docker 容器复制到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆