Philipp Winter
Philipp Winter

Reputation: 41

How to use custom DNS settings in Drone Docker plugin

I am using Drone behind a corporate proxy. When I'm building Docker containers there, Docker inserts the correct search server as well as DNS addresses into the container's /etc/resolv.conf. However, when using the Docker plugin, only the search server is patched whileas the nameservers are set to the default Google nameservers (8.8.8.8 resp. 8.8.4.4).

This obviously breaks my build as my corporate proxy DNS address cannot be resolved to its associated IP address.

Is this behavior intended and/or is there a workaround allowing me to connect to the internet through my proxy?

Upvotes: 2

Views: 3324

Answers (1)

Brad Rydzewski
Brad Rydzewski

Reputation: 2563

This can be resolved by providing the docker plugin configuration with your DNS server address. Note that the example below uses dummy IP addresses; please replace with your actual IP addresses.

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

If you are using the enterprise edition you can configure the following global environment variable:

- name: PLUGIN_CUSTOM_DNS
  value: 10.10.0.1,10.10.0.2


Why is this necessary?

Why does this issue surface for some configurations and not others? And in these instances, why does the DNS configuration not propagate to Docker in Docker? And why does this work with the default bridge but not user-defined networks? Unfortunately I cannot provide the root cause at this time, but can provide some information that might explain the behavior ...

It seems the logic for configuring DNS could be different depending on your version of Docker, Host Machine configuration, etc.

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.

It also seems the default bridge network does behave different than user-defined bridge networks by design:

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.

I wish I could provide a detailed technical root cause for this issue, and hope that someone can fill in the blanks for this answer. In the meantime, please use the workaround documented above.

Upvotes: 4

Related Questions