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 8 years ago
- Reactions: 9
- Comments: 64
Dear all,
We were facing the same issue. Starting a container with
docker run --dns
was working fine, the file/etc/resolv.conf
inherits the DNS servers of the host. However, using thedns
option indocker-compose.yml
leaves the default content:After adding
network_mode: bridge
in the YML file it works, the fileresolv.conf
gets the configured DNS servers. I thoughtbridge
was the option used by default.I wonder whether this could be documented somewhere alongside the
dns
option? 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.json
on 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_mode
to 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.
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
.dns
configuration only applies to the defaultbridge
network. If you have compose service to use a network (which is the case until you setnetwork_mode: bridge
the 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_opts
for this purpose, I haven’t checked thedefault
driver 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 resolvconf
fixed 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
dns
setting is still respected. From the Docker networking docs: