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=" > /etc/dnsmasq.conf
 RUN echo "conf-dir=/etc/dnsmasq.d" >> /etc/dnsmasq.conf
 RUN echo "user=root" >> /etc/dnsmasq.conf
 RUN echo "server=/a/" >> /etc/dnsmasq.conf
 #a for testing
 #RUN echo 'resolv-file=/etc/resolv.dnsmasq.conf' >> /etc/dnsmasq.conf
 #RUN echo "nameserver" > /etc/resolv.dnsmasq.conf
 # The on the previous line was not written incorrectly, but it was found that 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/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'
 build: ../../images/dnsmasq
 container_name: dns
 restart: always
 #env_file: ./config/.env
 #        volumes:
 #            - /etc/hosts:/etc/hosts
 #        dns:
 #            -
 - "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/ think soaddress=/a/

  2. Dnsmasq’slisten-address= 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.