如何在 Drone Docker 插件中使用自定义 DNS 设置

How to use custom DNS settings in Drone Docker plugin

我在公司代理后面使用 Drone。 当我在那里构建 Docker 容器时,Docker 将正确的搜索服务器和 DNS 地址插入容器的 /etc/resolv.conf。但是,当使用 Docker plugin 时,只有搜索服务器被修补,而名称服务器被设置为默认的 Google 名称服务器(8.8.8.8 resp. 8.8.4.4)。

这显然破坏了我的构建,因为我的公司代理 DNS 地址无法解析为其关联的 IP 地址。

此行为是否有意and/or是否有允许我通过代理连接到互联网的解决方法?

这可以通过在 docker 插件配置中提供您的 DNS 服务器地址来解决。请注意,下面的示例使用了虚拟 IP 地址;请替换为您的实际 IP 地址。

pipeline:
  docker:
    image: plugins/docker
    custom_dns: [ 10.10.0.1, 10.10.0.2 ]

如果您使用的是企业版,您可以配置以下全局环境变量:

- name: PLUGIN_CUSTOM_DNS
  value: 10.10.0.1,10.10.0.2


为什么这是必要的?

为什么这个问题在某些配置上出现,而在其他配置上却没有?在这些情况下,为什么 DNS 配置没有传播到 Docker 中的 Docker?为什么这适用于默认网桥而不适用于用户定义的网络?不幸的是,我目前无法提供根本原因,但可以提供一些可能解释该行为的信息...

根据您的 Docker 版本、主机配置等,配置 DNS 的逻辑似乎可能有所不同。

The exact details of how Docker manages the DNS configurations inside the container can change from one Docker version to the next. So you should not assume the way the files such as /etc/hosts, /etc/resolv.conf are managed inside the containers and leave the files alone and use the following Docker options instead.

似乎默认桥接网络的行为在设计上确实与用户定义的桥接网络不同:

In order to maintain backward compatibility, the DNS configuration in default bridge network is retained with no behavioral change. Please refer to the DNS in default bridge network for more information on DNS configuration in the default bridge network.

我希望我能提供这个问题的详细技术根源,并希望有人能填补这个答案的空白。同时,请使用上面记录的解决方法。