Home  >  Q&A  >  body text

Docker for Mac 创建的dnsmasq容器连不上/不工作的问题

在使用docker for mac构建了一个dnsmasq的Container, 但是发现53端口似乎无法连接, 使用dig各种超时

这是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供测试用

#RUN echo 'resolv-file=/etc/resolv.dnsmasq.conf' >> /etc/dnsmasq.conf
#RUN echo "nameserver 127.0.0.11" > /etc/resolv.dnsmasq.conf
#上一行出现了127.0.0.11并不是写错, 而是发现docker for mac的container的/etc/resolv.conf里面确实出现了127.0.0.11, 并且这个上面是可以解析域名的, 所以才试图这么尝试过这个配置

RUN yum install nc -y

RUN yum clean all

EXPOSE 53
EXPOSE 53/udp

#CMD ["nc", "-l",  "53"] #tcp调试
#CMD ["nc", "-l", "-u",  "53"] #udp调试

CMD ["/usr/sbin/dnsmasq", "-d"]

这是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"

各种端口映射应该是没有问题的, 宿主机上运行和访问:

容器内运行和访问:

淡淡烟草味淡淡烟草味2708 days ago802

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-04-24 16:01:22

    After @Youming’s suggestion, the fundamental problem is that there is a problem with the configuration of dnsmasq rather than a problem with docker. There are the following points:

    1. Wrong server=/a/127.0.0.1 当成了 address=/a/127.0.0.1

    2. dnsmasq of listen-address=0.0.0.0 似乎是有bug的, 必须listen到精确的网卡的IP地址或者干脆不要这行listen-address

    After changing it, it will work normally

    reply
    0
  • Cancelreply