gpt4 book ai didi

docker - 如何为同一项目中的不同构建指定不同的 .dockerignore 文件?

转载 作者:IT老高 更新时间:2023-10-28 12:37:39 25 4
gpt4 key购买 nike

我曾经在 .dockerignore 中列出 tests 目录,这样它就不会被包含在我用来运行 Web 服务的镜像中。

现在我正在尝试使用 Docker 来运行我的单元测试,在这种情况下,我希望包含 tests 目录。

我检查了 docker build -h 并没有发现相关的选项。

我该怎么做?

最佳答案

Docker 19.03 为此提供了解决方案。

The Docker client tries to load <dockerfile-name>.dockerignore first and then falls back to .dockerignore if it can't be found. So docker build -f Dockerfile.foo . first tries to load Dockerfile.foo.dockerignore.

设置DOCKER_BUILDKIT=1当前需要环境变量才能使用此功能。此标志可与 docker compose 一起使用自从 1.25.0-rc3also specifying COMPOSE_DOCKER_CLI_BUILD=1 .

另见 comment0 , comment1 , comment2


来自 Mugen comment ,请注意

the custom dockerignore should be in the same directory as the Dockerfile and not in root context directory like the original .dockerignore

打电话时

DOCKER_BUILDKIT=1
docker build -f /path/to/custom.Dockerfile ...

您的.dockerignore文件应该在

/path/to/custom.Dockerfile.dockerignore

关于docker - 如何为同一项目中的不同构建指定不同的 .dockerignore 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40904409/

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