Set docker dns to another container

I am setting up a docker compose,
I have 2 services defined, a dns server (using dnsmasq) and an apache server
The definition is as follows:

version: '3.1'
services:
    dnsmasq:
        image: jpillora/dnsmasq
        environment:
            - USER=example
            - PASS=example
        restart: always
        dns:
            - 127.0.0.1
        ports:
            - "53:53"     
            - "53:53/udp" 
        container_name: dnsmasq
        volumes:
            - ./dns/dnsmasq.conf:/etc/dnsmasq.conf
    apache:
        build:
            context: php7.2
            dockerfile: Dockerfile
        container_name: apache2
        dns:
            - dnsmasq
        ports:
            - "80:80" 
            - "443:443"   
        volumes:
            - /var/www:/var/www

However setting the apache dns to dnsmasq container name doesnt seem to be working. Is there a way to accomplish what I want?

Thanks

1 Like

Never mind, I figurd it out by creating a custom network and setting a static ip on the dnsmasq contianer and using that static ip for the dns setting

It really works this way, however making things hard-coded is not an option when you need to run several instances of your app simultaneously with different DNS settings.