1. 拉取鏡像
docker pull coredns/coredns
2. 創建配置文件
mkdir -p /etc/coredns
nano /etc/coredns/corefile
.:53 {
hosts {
10.0.0.1 my.host.com // 你域名和ip
fallthrough
}
forward . 114.114.114.114:53 //你的備用 dns
log
}
也可以將 hosts 放在單獨一個文件中
.:53 {
hosts /etc/coredns/hostsfile {
fallthrough
}
forward . 8.8.8.8:53
log
}
# cat hostsfile
10.0.0.1 example1.org
3. 啟動服務
docker run -it -d --name coredns --net=host -v /etc/coredns:/etc/coredns/ coredns/coredns:latest -conf /etc/coredns/corefile
4. 測試
dig @127.0.0.1 -p 53 my.host.com
全部命令
rm -rf /etc/coredns && mkdir -p /etc/coredns && echo "
.:53 {
hosts {
# ip host
127.0.0.1 host.com
fallthrough
}
# forward . dns-1 dns-2
forward . 114.114.114.114
log
}
">> /etc/coredns/corefile && docker run -it -d --name dns --net=host -v /etc/coredns:/etc/coredns/ coredns/coredns:latest -conf /etc/coredns/corefile