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

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

问题描述

以下 Dockerfile 包含四个 COPY 层:

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天全站免登陆