如何使用 Dockerfile 在一层中复制多个文件? [英] How to copy multiple files in one layer using a Dockerfile?

查看:63
本文介绍了如何使用 Dockerfile 在一层中复制多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 Dockerfile 包含四个 COPY 层:

The following Dockerfile contains four COPY layers:

COPY README.md ./
COPY package.json ./
COPY gulpfile.js ./
COPY __BUILD_NUMBER ./

如何使用一层来复制这些文件?尝试了以下方法:

How to copy these files using one layer instead? The following was tried:

COPY [
    "__BUILD_NUMBER ./",
    "README.md ./",
    "gulpfile ./",
    "another_file ./",
]

推荐答案

COPY README.md package.json gulpfile.js __BUILD_NUMBER ./

COPY ["__BUILD_NUMBER", "README.md", "gulpfile", "another_file", "./"]

您还可以在源文件规范中使用通配符.查看文档了解更多详情.

You can also use wildcard characters in the sourcefile specification. See the docs for a little more detail.

目录很特别!如果你写

COPY dir1 dir2 ./

实际上是这样的

COPY dir1/* dir2/* ./

如果您想在单个命令中复制目标目录下的多个目录(而不是它们的内容),您需要设置构建上下文,以便您的源目录位于公共父目录下,然后 COPY那个父母.

If you want to copy multiple directories (not their contents) under a destination directory in a single command, you'll need to set up the build context so that your source directories are under a common parent and then COPY that parent.

这篇关于如何使用 Dockerfile 在一层中复制多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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