Docker Community Forums

Share and learn in the Docker community.

Set docker dns to another container


(Harmar21) #1

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


(Harmar21) #2

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