如何为同一项目中的不同版本指定不同的.dockerignore文件? [英] How to specify different .dockerignore files for different builds in the same project?

查看:80
本文介绍了如何为同一项目中的不同版本指定不同的.dockerignore文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经在 .dockerignore 中列出 tests 目录,以便它不会包含在映像中

I used to list the tests directory in .dockerignore so that it wouldn't get included in the image, which I used to run a web service.

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

Now I'm trying to use Docker to run my unit tests, and in this case I want the tests directory included.

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

I've checked docker build -h and found no option related.

我该怎么做?

推荐答案

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

Docker 19.03 shipped a solution for this.


Docker客户端尝试加载< dockerfile-name>。 dockerignore 首先,然后退回到 .dockerignore (如果找不到)。因此 docker build -f Dockerfile.foo。首先尝试加载 Dockerfile.foo.dockerignore

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-rc3 ,由也指定 COMPOSE_DOCKER_CLI_BUILD = 1

Setting the DOCKER_BUILDKIT=1 environment variable is currently required to use this feature. This flag can be used with docker compose since 1.25.0-rc3 by also specifying COMPOSE_DOCKER_CLI_BUILD=1.

另请参见:

  • https://github.com/moby/moby/issues/12886#issuecomment-480575928
  • https://github.com/moby/moby/issues/12886#issuecomment-518843764
  • https://github.com/moby/moby/issues/12886#issuecomment-523706042

这篇关于如何为同一项目中的不同版本指定不同的.dockerignore文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆