如何从 Dockerfile 将文件夹复制到 docker 映像? [英] How to copy folders to docker image from Dockerfile?

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

问题描述

我在 Dockerfile 中尝试了以下命令:COPY */ 并对结果感到非常惊讶.似乎天真的 docker 代码遍历 glob 中的目录,然后将每个文件转储到目标目录中,同时恭敬地忽略我的目录结构.

I tried the following command in my Dockerfile: COPY * / and got mighty surprised at the result. Seems the naive docker code traverses the directories from the glob and then dumps the each file in the target directory while respectfully ignoring my directory structure.

至少我是这样理解这张票的,它肯定与结果相对应我有.

At least that is how I understand this ticket and it certainly corresponds to the result I got.

我想这种行为仍然存在的唯一原因一定是应该有其他方法来完成.但是小脑袋的熊要怎么理解就不是那么容易了,有谁知道吗?

I guess the only reason this behavior can still exist must be that there is some other way this should be done. But it is not so easy for a bear of very little brain to understand how, does anyone know?

推荐答案

使用 ADD (文档)

ADD 命令可以接受为 <src> 参数:

Use ADD (docs)

The ADD command can accept as a <src> parameter:

  1. 构建文件夹的文件夹(与您的 Dockerfile 相同的文件夹).然后,您将在 Dockerfile 中添加一行,如下所示:
  1. A folder within the build folder (the same folder as your Dockerfile). You would then add a line in your Dockerfile like this:

ADD folder /path/inside/your/container

  1. 主机文件系统中任意位置的单文件存档.要创建存档,请使用以下命令:

tar -cvzf newArchive.tar.gz /path/to/your/folder

然后你会像这样在你的 Dockerfile 中添加一行:

You would then add a line to your Dockerfile like this:

ADD /path/to/archive/newArchive.tar.gz  /path/inside/your/container

注意事项:

  • ADD 将自动提取您的存档.
  • 尾部斜杠的存在/不存在很重要,请参阅链接文档
  • ADD will automatically extract your archive.
  • presence/absence of trailing slashes is important, see the linked docs

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

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