如何将文件从dockerfile复制到主机? [英] How to copy files from dockerfile to host?

查看:1008
本文介绍了如何将文件从dockerfile复制到主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当dockerfile成功构建时,我想获取一些文件,但它不会将文件从容器复制到主机.

I want to get some files when dockerfile built successfully, but it doesn't copy files from container to host.

这意味着当我构建了dockerfile时,这些文件已经被托管了.

That means when I have built dockerfile, the files already be host.

推荐答案

不支持将文件从Dockerfile"复制到主机. Dockerfile只是指定如何构建映像的配方.

Copying files "from the Dockerfile" to the host is not supported. The Dockerfile is just a recipe specifying how to build an image.

构建时,可以将文件从主机复制到要构建的映像(使用 COPY指令 ADD )

When you build, you have the opportunity to copy files from host to the image you are building (with the COPY directive or ADD)

您还可以使用

You can also copy files from a container (an image that has been docker run'd) to the host with docker cp (atually, the cp can copy from the host to the container as well)

如果要返回到主机,则可能会在构建过程中生成一些文件(例如

If you want to get back to your host some files that might have been generated during the build (like for example calling a script that generates ssl), you can run a container, mounting a folder from your host and executing cp commands.

例如,请参见以下 getcrt脚本.

docker run -u root --entrypoint=/bin/sh --rm -i -v ${HOME}/b2d/apache:/apache apache << COMMANDS
pwd
cp crt /apache
cp key /apache
echo Changing owner from \$(id -u):\$(id -g) to $(id -u):$(id -u)
chown -R $(id -u):$(id -u) /apache/crt
chown -R $(id -u):$(id -u) /apache/key
COMMANDS

COMMANDS之间的所有内容都是在容器上执行的命令,包括正在复制到主机${HOME}/b2d/apache文件夹中的cp命令,这些文件夹在/apache中与-v ${HOME}/b2d/apache:/apache一起安装在容器中.

Everything between COMMANDS are commands executed on the container, including cp ones which are copying on the host ${HOME}/b2d/apache folder, mounted within the container as /apache with -v ${HOME}/b2d/apache:/apache.

这意味着每次在容器中的/apache上复制任何内容时,实际上都是在主机上的${HOME}/b2d/apache中复制!

That means each time you copy anything on /apache in the container, you are actually copying in ${HOME}/b2d/apache on the host!

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

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