我曾经在 .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. Sodocker build -f Dockerfile.foo .
first tries to loadDockerfile.foo.dockerignore
.
设置DOCKER_BUILDKIT=1
当前需要环境变量才能使用此功能。此标志可与 docker compose
一起使用自从 1.25.0-rc3由 also 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/