Q:

docker-compose does not update resolv.conf

I have the following simplified docker-compose file:

version: '2'
services:
    test.base:
        container_name: test.base
        image: docker.pnet.ch/r-base:latest
        restart: on-failure
        networks:
            - mynet
        dns: 192.168.198.2
        dns_search:
            - pext.ch
            - pnet.ch
networks:
    mynet:
        driver: bridge
        driver_opts:
            com.docker.network.enable_ipv4: "true"
        ipam:
            driver: default
            config:
                - subnet: 192.168.198.0/24
                  gateway: 192.168.198.1

With this I expect to have the following entries in the containers /etc/resolv.conf:

search pext.ch pnet.ch
nameserver 192.168.198.2

But instead I have the following:

search pext.ch pnet.ch
nameserver 127.0.0.11
options ndots:0

When I manually start the container using docker run with --dns 192.168.199.2 /etc/resolv.conf contains a nameserver with the given ip address.
Is there anything wrong with my docker-compose file or is it a bug in docker-compose?
I'm using docker version 1.10.3 on RHEL and docker-compose 1.9.0

A:

Networking in Docker Compose file format v2 it's different from version 1, and I think that's the actual problem. It's also confusing that a docker run ... command works while the docker-compose ... don't. I experienced the same issue.
What I found is that Docker Compose v2 creates a user-defined network for the containers defined in the docker-compose.yml file, whereas docker run ... by default uses the bridged network, named docker0 on the host. Also, with custom networks docker uses an embedded DNS server (that's the 127.0.0.11). The docs say:

The IP addresses passed via the --dns option is used by the embedded DNS server to forward the DNS query if embedded DNS server is unable to resolve a name resolution request from the containers. These --dns IP addresses are managed by the embedded DNS server and will not be updated in the container's /etc/resolv.conf file.

I think the last line answers your question. Anyway, your container should be resolving correctly, doesn't it?

A:

I used volumes: to work around this problem. In your case:
version: '2'
services:
    test.base:
        container_name: test.base
        image: docker.pnet.ch/r-base:latest
        restart: on-failure
        networks:
            - mynet
        volumes:
            - ./resolv.conf:/etc/resolv.conf

Where the ./resolv.conf file contains what exactly you expected as:
search pext.ch pnet.ch
nameserver 192.168.198.2

Here assumes the resolv.conf file is on the same folder as your docker-compose file.

