The dnsmasq container created by Docker for Mac is not connected/does not work.

  docker, question

In using docker for mac to build a dnsmasq Container, but found that port 53 seemed unable to connect, dig was used for various timeouts.

This is dockerfile.

FROM centos:6.8
 
 RUN yum update -y && yum install -y dnsmasq
 
 RUN echo "listen-address=0.0.0.0" > /etc/dnsmasq.conf
 RUN echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
 RUN echo "user=root" >> /etc/dnsmasq.conf
 RUN echo "server=/a/127.0.0.1" >> /etc/dnsmasq.conf
 #a for testing
 
 #RUN echo 'resolv-file=/etc/resolv.dnsmasq.conf' >> /etc/dnsmasq.conf
 #RUN echo "nameserver 127.0.0.11" > /etc/resolv.dnsmasq.conf
 # The 127.0.0.11 on the previous line was not written incorrectly, but it was found that 127.0.0.11 did appear in/etc/resolve.conf of container of docker for mac, and the domain name can be resolved on this, so we tried this configuration.
 
 RUN yum install nc -y
 
 RUN yum clean all
 
 EXPOSE 53
 EXPOSE 53/udp
 
 #CMD ["nc", "-l", "53"] #tcp debugging
 # cmd ["nc", "l", "u", "53"] # udp debugging
 
 CMD ["/usr/sbin/dnsmasq", "-d"]

This is docker-compose

version: '2'
 
 services:
 dns:
 build: ../../images/dnsmasq
 container_name: dns
 restart: always
 #env_file: ./config/.env
 #        volumes:
 #            - /etc/hosts:/etc/hosts
 #        dns:
 #            - 127.0.0.1
 ports:
 - "53:53"
 - "53:53/udp"

All kinds of port mapping should be no problem, host machine running and access:

图片描述

Operation and Access in Container:

图片描述

after@ ClearThe basic problem of this is the configuration of dnsmasq instead of docker. There are the following points:

  1. Wrong handleserver=/a/127.0.0.1I think soaddress=/a/127.0.0.1

  2. Dnsmasq’slisten-address=0.0.0.0It seems that there is a bug, which must be listen to the exact IP address of the network card or not at all.listen-address

After changing it, you can work normally.