compose: dns configuration option does not work on docker-compose==1.6.0
Step 1:
$ cat docker-compose.yml
version: "2"
services:
testnet:
image: fedora:23
dns: 192.168.1.1
command: /bin/bash
Step 2:
$ docker-compose -f docker-compose.yml run testnet
Step 3:
[root@bbd9f61098fb /]# cat /etc/resolv.conf
search xxx.yyy.tld
nameserver 127.0.0.11
options ndots:0
As you can see, dns option is ignored by docker-compose and some garbage is set instead. This prevents my containers from starting up because they require to use mentioned DNS server. BTW, what kind of shit is 127.0.0.11, and how it get to resolve.conf?
With version 1 of yaml file everything is working as expected (nameserver is set correctly).
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 10
- Comments: 65 (1 by maintainers)
Dear all,
We were facing the same issue. Starting a container with
docker run --dnswas working fine, the file/etc/resolv.confinherits the DNS servers of the host. However, using thednsoption indocker-compose.ymlleaves the default content:After adding
network_mode: bridgein the YML file it works, the fileresolv.confgets the configured DNS servers. I thoughtbridgewas the option used by default.I wonder whether this could be documented somewhere alongside the
dnsoption? I couldn’t find the solution until reading all different workarounds here.+1 same issue for me
this issue is not solved @mmarzantowicz open it again,
Resolved my issue by creating and adding the below to
/etc/docker/daemon.jsonon the Centos:7 host.This marks year five.
Please, reopen this. I also can confirm this issue on Ubuntu 14.04. Restarting Docker service is what solves the issue.
I am not completely sure what is wrong but I am not able to add e.g. dns record to /etc/hosts at all even I am using just docker-compose up -d on a single docker-compose.yml with one service.
I am trying to setup nexus repo:
I have verified that it works with --dns flag on normal docker run
However, it does not work when I create a network manually like this:
In this case, it is not there. Very interesting … Why specifying network prevents me from adding DNS record to /etc/hosts?
Adding this into docker-compose.yml solved my DNS issues:
Can somebody reopen this? This is 5 years already, people still having problem with it. @ulyssessouza
Same problem, docker version 17.04.0-ce, docker-compose version 1.12.0, build b31ff33
I had the same problem under docker-compose 1.11. Solved adding
network_modeto the yaml configuration.@uy-rrodriguez I also always thought the default network mode was bridge, but turns out it’s not the case. It is mentioned in the compose documentation:
This issue is a critical one, please open it ASAP. Without ability to properly define DNS, compose is a harming manner, especially on production. Please consider removing 1.6 until problem is not fixed.
necrobumping as this still seems to be an issue (as described above).
As far as I can tell this is a combination of the following factors:
dns_enabled, the built-in DNS server is activated and used/etc/resolv.confand silently takes precedence over anydns:options, making them ineffectivesubnets.gateway(we do not want a gateway for all networks and even when we do we it’s often desired to be separate from DNS)dns_enabled: true(thus force built-in DNS) with no (discoverable to me, at least) way to disable itThe only identified workaround and way to actually use service-specific DNS servers and sidestep the (entirely undesired by us) built-in DNS is to use mounts to overwrite
/etc/resolv.confmanually. This works somewhat but is cumbersome, error-prone, and adds unnecessary runtime overhead. Unfortunately,configs don’t seem to work and get overwritten.Either of the following suggestions seem like it would improve the situation greatly:
dns:/--dnstake take precendence over network-defined nameserversdns:/--dnsis providedservicesbridgedriver_opts(might require changes in moby?)For me the problem is not fix. When I with a ‘docker run --dns’ command, the DNS work but not with the docker-compose file.
Second this. Running on debian stretch:
dns resolving for internal addresses is not working:
Container:
Host:
Starting regular docker run with --dns option works.
I investigate on my side and I found my problem. I cannot speak for everybody but here is what I found:
Setting the property: net: “host” in the docker-compose file or --net host in the docker run command will result in the ports not displayed when doing a docker ps. It is normal because setting this property let the container inherits the host network settings.
As per documentation, this configuration is not recommend so I change it to: net: “bridge” (default if not specified) and added a DNS on my docker host to solve my communication problems.
@mmarzantowicz also pls confirm if you are using fedora/centos/RHEL ? If yes, we have a known issue and the workaround is to disable
firewalld.Thank you @ndeloof for you response. I checked the
driver_optsbut found no DNS-related options.https://docs.docker.com/engine/reference/commandline/network_create/ https://docs.docker.com/network/network-tutorial-standalone/
Is there any other undocumented DNS-related options?
dnsconfiguration only applies to the defaultbridgenetwork. If you have compose service to use a network (which is the case until you setnetwork_mode: bridgethe DNS configuration has no impact on container. This is not specific to compose. Ability to customize DNS resolution would have to apply on the network itself. Might be possible if you set adequatedriver_optsfor this purpose, I haven’t checked thedefaultdriver supports this.See the related posts, there is a PR opened to fix it, but not yet merged.
Setting the dns in docker-compose.yml is one option. The real problem is the /etc/resolv.conf file on the host system, this generated by a network manager and should be a symlink. Docker containers use this file on the host system:
In my case upgrading to Ubuntu 17.04 probably triggered NetworkManager to misconfigure /etc/resolv.conf. As is shown here,
sudo dpkg-reconfigure resolvconffixed the issue for me.You can be right if DNS are down by docker’s bug: https://github.com/docker/docker/issues/11407 But I’ll wait till this one is resolved and then try again.
Till then docker, so long, and thanks for all the fish…
DNS is configured differently when using a custom network (as is the case when using v2 of the Compose file format), but the
dnssetting is still respected. From the Docker networking docs:@mmarzantowicz btw, if you can read about the embedded-DNS server (since you seem to be interested in knowing about 127.0.0.11 😃 ) : https://github.com/docker/docker/blob/ef52a53c34d9f128d9435d031442509837c25c02/docs/userguide/networking/dockernetworks.md#docker-embedded-dns-server