.dockerignore无法将文件包含在具有!**/*.extension模式的子目录中 [英] .dockerignore fails to include files in subdirectories with !**/*.extension pattern
问题描述
我遇到了 .dockerignore
文件.这是我的项目结构:
I'm having trouble with the .dockerignore
file. This is my project structure:
file.sh
file.js
file.go
file.py
subdir/
file2.go
file2.py
.dockerignore
Dockerfile
根据 .dockerignore
文档:
(...),您可能想要指定要包含在上下文中的文件,而不是要排除的文件.为此,将*指定为第一个模式,然后指定一个或多个!异常模式.
(...) you may want to specify which files to include in the context, rather than which to exclude. To achieve this, specify * as the first pattern, followed by one or more ! exception patterns.
并且:
以!开头的行(感叹号)可用于排除例外情况.
Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions.
最后:
Docker还支持特殊的通配符字符串**,该字符串与任意数量的目录(包括零个)匹配.例如,**/*.go将排除在所有目录(包括构建上下文的根目录)中找到的所有以.go结尾的文件.
Docker also supports a special wildcard string ** that matches any number of directories (including zero). For example, **/*.go will exclude all files that end with .go that are found in all directories, including the root of the build context.
基于此,这是我的 .dockerignore
文件:
Based on that, this is my .dockerignore
file:
# ignore everything
*
# whitelist
# ---------
# python files
!**/*.py
构建并运行容器并检查文件时,我得到了:
When I build and run the container and inspect the files, I get this:
file.py
缺少 subdir
目录,应该包含 subdir/file2.py
.如果我在 .dockerignore
中添加!subdir/**/.py
,它会起作用,但是我的想法是在其中包含任何 .py
文件任何子目录.
The subdir
directory is missing, subdir/file2.py
should be included. It works if I add !subdir/**/.py
to my .dockerignore
, but the idea is to include any .py
file in any subdirectory.
这是容器中应该存在的文件结构:
This is the file structure that should be present in the container:
file.py
subdir/
file2.py
这是怎么回事?
推荐答案
我发现了一些提到此确切问题的问题,例如:
I found a few issues that mention this exact problem, like these:
.dockerignore中的异常模式不支持通配符目录 dockerignore不尊重特殊通配符**" (评论)
似乎很快就不会修复:(
And it seems like it's not gonna be fixed any time soon :(
这篇关于.dockerignore无法将文件包含在具有!**/*.extension模式的子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!