gpt4 book ai didi

docker - .dockerignore 无法在带有 !**/*.extension 模式的子目录中包含文件

转载 作者:行者123 更新时间:2023-12-02 18:14:04 25 4
gpt4 key购买 nike

我在使用 .dockerignore 时遇到问题文件。这是我的项目结构:

file.sh
file.js
file.go
file.py
subdir/
file2.go
file2.py
.dockerignore
Dockerfile

根据 .dockerignore documentation :

(...) 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 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文件:
# ignore everything
*

# whitelist
# ---------

# python files
!**/*.py

当我构建并运行容器并检查文件时,我得到以下信息:
file.py
subdir目录丢失, subdir/file2.py应该包括在内。如果我添加 !subdir/**/.py 就可以了到我的 .dockerignore ,但想法是包含任何 .py文件在任何子目录中。

这是容器中应该存在的文件结构:
file.py
subdir/
file2.py

这里发生了什么?

最佳答案

我发现了一些提到这个确切问题的问题,如下所示:

Exception patterns in .dockerignore do not support wildcard directories
dockerignore does not respect the "special wildcard **" (评论)

而且它似乎不会很快修复:(

关于docker - .dockerignore 无法在带有 !**/*.extension 模式的子目录中包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56594502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com