复制忽略文件

注意

此检查是实验性的,默认情况下未启用。要启用它,请参阅 实验性检查

输出

Attempting to Copy file "./tmp/Dockerfile" that is excluded by .dockerignore

描述

当您在 Dockerfile 中使用 Add 或 Copy 指令时,应确保要复制到镜像中的文件不匹配 .dockerignore 中的模式。

.dockerignore 文件中的模式匹配的文件在构建镜像时不会出现在上下文中。尝试复制或添加上下文中不存在的文件将导致构建错误。

示例

使用给定的 .dockerignore 文件:

*/tmp/*

❌ 错误:尝试复制被 .dockerignore 排除的文件 "./tmp/Dockerfile"

FROM scratch
COPY ./tmp/helloworld.txt /helloworld.txt

✅ 很好:复制一个未被 .dockerignore 排除的文件

FROM scratch
COPY ./forever/helloworld.txt /helloworld.txt