DOCKER DNS change /etc/resolv.conf file

I am using a docker-compose command to create and start my containers.

My Docker Version

docker --version
Docker version 17.09.0-ce, build afdb6d4

My Docker-Compose version

docker-compose --version
docker-compose version 1.16.1, build 6d1ac21

The .yml file that I’m using looks something like this: (Note that I’ve just shortened it to take sensitive things out)

---
services:
  zookeeper:
    image: "zookeeper"
  server-1:
    cap_add:
    - "NET_ADMIN"
  server-0:
    cap_add:
    - "NET_ADMIN"
    dns:
    - 8.8.8.8
    - 9.9.9.9
    environment:
      SERVER_ID: 0
      NETEM_HOSTS: ""
      LOSS_VALUES: ""
      MAX_RATE_VALUES: ""
      DELAY_VALUES: ""
    image: "cloud.mycompany.com:5000/server-0:latest"
  fakedns:
    image: "cloud.mycompany.com:5000/fakedns:latest"
version: "3.3"

Then I start using:

docker-compose --file compose.yml up -d

My Question is this:

  1. 1} After containers come up… when I go into a container, for e.g. in this case server-0, I don’t see the /etc/resolv.conf file updated to use these nameservers. Instead it uses the embedded dns of docker which is 127.0.0.11

  2. 2} How do I make sure that it uses what I specify in file that is used by docker-compose

  3. 3} I tried to do this with the command and it seems to work, but I need to do from compose-file
    docker run -p 4000:53 --dns=8.8.8.8 cloud.mycompany.com:5000/server-0:latest

  4. 4} Ideally, I want it to have the IP address of the container ‘fakedns’ so that it uses this one instead of the embedded one @127.0.0.11

1 Like

From my own experiments, your --dns gets added to dockers internal dns server 127.0.0.11

However I agree this is confusing, and I think resolv.conf should have a comment included to say that it has been included. I created a pull request for this https://github.com/docker/libnetwork/pull/2005

What would also be useful, is if you could inspect the dns server from the docker command line.

The question is from 2017 & now it’s 2021. I’m using docker 19.03.13 & still face the same issue.
The workaround is to bind mount resolv.conf from host.
Make sure that 127.0.0.11 is added on hosts’s resolv.conf.
Is there any solution to add DNS resolver entry using compose / stack file?

1 Like