处理具有不同隐私设置的多个Docker容器

I have been working on this project recently in which a couple of docker containers are built along the way and they end up being sent to different third-party servers. Due to privacy reasons, some specific files must not be sent to particular servers. Hence, each container has its own blacklist of files it should not accept inside. This should be handled by the .dockerignore files, except that my .dockerignores got, well, ignored (no pun intended).

我最近一直在从事这个项目,在该项目中,沿途构建了两个Docker容器,它们最终被发送到不同的第三方服务器。 由于隐私原因,某些特定文件不能发送到特定服务器。 因此,每个容器都有其自己不应在内部接受的文件黑名单。 这应该由.dockerignore文件处理,除了我的.dockerignores被很好地忽略(没有双关语)。

It took me hours to find the solution, which, obviously, turned out to be a one-liner.

我花了几个小时才找到解决方案,很显然,这是一成不变的。

I hope I can save you some miserable time by suggesting you set the environmental variable DOCKER_BUILDKIT to 1 straight away.

希望建议您立即将环境变量DOCKER_BUILDKIT设置为1,以节省一些时间。

That’s it, that’s the trick. If you wish, feel free to read on for some background.

就是这样,这就是窍门。 如果您愿意,请随时阅读一些背景知识。

Image for post

According to the Docker documentation, when the container is being built, the Docker client looks for a .dockerignore file matching the Dockerfile’s name. Hence, if you have a Dockerfile called my_app_dockerfile, Docker looks for my_app_dockerfile.dockerignore. If it doesn’t exist, then it looks for simply .dockerignore. Unfortunately, this did not work for me. I had two Dockerfiles with the matching .dockerignores, but none of the latter was detected.

按照多克尔文档,当容器被建成,多克尔客户端查找.dockerignore文件匹配Dockerfile的名字。 因此,如果您有一个名为my_app_dockerfile ,则Docker将寻找my_app_dockerfile.dockerignore 。 如果不存在,那么它只会.dockerignore 。 不幸的是,这对我没有用。 我有两个带有匹配的.dockerignores的Dockerfile,但是没有一个被检测到。

Browsing the web for the answer has finally led me to this github issue comment explaining that .dockerignores indeed work as described in the docs as long as the DOCKER_BUILDKIT environmental variable is set to 1. But what is it?

浏览网页终于找到了这个github问题评论,解释了.dockerignores确实按照文档中的描述工作,只要DOCKER_BUILDKIT环境变量设置为1。但这是什么?

Docker BuildKit is a relatively new feature, fully released in mid-2019 with Docker 19.03. Its aim is to increase the performance of container-building by reading and building Dockerfile lines in parallel, among others. It turns out it’s also needed for .dockerignore-detection to work properly.

Docker BuildKit是一个相对较新的功能,已在Docker 19.03中于2019年中全面发布。 其目的是通过并行读取和构建Dockerfile行来提高容器构建的性能。 事实证明,.dockerignore-detection正常工作也需要。

On a MacOS, you can enable BuildKit permanently from Docker Desktop by going to preferences — deamon — advanced and adding the features field to the json with buildkit set to true:

在MacOS上,您可以通过以下方式从Docker桌面永久启用BuildKit:转到首选项-deamon-高级,并将features字段添加到json, buildkit设置为true

Image for post
Image for post

Thanks for reading! I hope you will find this piece of advice useful. If you liked this post, try one of my other articles. Can’t choose? Pick one of these:

谢谢阅读! 我希望您会发现此建议有用。 如果您喜欢这篇文章,请尝试我的其他文章之一。 无法选择? 选择以下之一:

翻译自: https://medium.com/swlh/handling-multiple-docker-containers-with-different-privacy-settings-e6c4c0c243c3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值