Docker sets up DNS server in 1 minute

Here we use the docker version docker-dnsmasq corresponding to dnsmasq.

Guide to Use

Download Mirror

docker pull docker-dnsmasq

Create the simplest configuration /opt/dnsmasq.conf

#dnsmasq config, for a complete example, see:
#dns parsing log
#Define Host to IP Mapping

Run Container

docker run \
    --name dnsmasq \
    -d \
    -p 53:53/udp \
    -p 8080:8080 \
    -v /opt/dnsmasq.conf:/etc/dnsmasq.conf \
    --log-opt "max-size=100m" \
    -e "HTTP_USER=admin" \
    -e "HTTP_PASS=admin" \
    --restart always \

Parameter Description

Name Explain
max-size Maximum Log Save
HTTP_USER Username
HTTP_PASS Logon Password

Visit Pull http://localhost:8080

  • Log in with admin/admin account password.
dnsmasq interface

DNS configuration

  • In/etc/Resolv.confAdd the following two sentences before the file
  • Adding only DNS will fail resolution
nameserver          #Required
nameserver      #Mandatory [local primary network card]


  • This machine is configured like any other machine
  • Required before it will take effect because DNS resolution will resolve from top to bottom
root@center ~# ping h1
PING h1 ( 56(84) bytes of data.
64 bytes from ( icmp_seq=1 ttl=64 time=0.155 ms
64 bytes from ( icmp_seq=2 ttl=64 time=0.203 ms
--- h1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.155/0.179/0.203/0.024 ms

Increase Resolution

  • Click Save to take effect automatically in a few seconds

Be careful

  • It is recommended to keep the hostname of other machines as configured above
  • Otherwise, the following problems may occur
root@asdf ~# ping h0
ping: h0: Name or service not known

Tags: Docker DNS network

Posted on Sat, 13 Jun 2020 12:52:38 -0400 by sujithnair