docker搭建dnsmasq服务的实现
作者:douchunrong
本文将指导读者如何使用Docker搭建DNSmasq服务,通过简单的步骤和详细的说明,帮助读者快速在Docker环境中部署DNSmasq,具有一定的参考价值,感兴趣的可以了解一下
Dockerfile 编写
mkdir -p /data/docker/dns && cd /data/docker/dns && vim Dockerfile
FROM centos:centos7.9.2009 as builder ENV GOROOT=/usr/local/go ENV GOBIN=/usr/local/go/bin ENV GOPATH=/usr/local/go/gopath ENV GOPROXY=https://goproxy.cn,https://goproxy.io,direct ENV PATH=$PATH:$GOBIN:$GOPATH/bin WORKDIR /opt RUN yum -y update && yum -y install wget git \ && wget --progress=bar:force https://studygolang.com/dl/golang/go1.19.5.linux-amd64.tar.gz \ && tar -zxvf go1.19.5.linux-amd64.tar.gz -C /usr/local \ && rm -f go1.19.5.linux-amd64.tar.gz \ && git clone https://github.com/jpillora/webproc.git \ && cd webproc \ && go build -o webproc -v . FROM centos:centos7.9.2009 MAINTAINER traynordou@163.com ENV DNSMASQ_CONF=/etc/dnsmasq.conf COPY docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh COPY --from=builder /opt/webproc/webproc /usr/bin/webproc RUN yum -y install dnsmasq \ && cp /etc/dnsmasq.conf /etc/dnsmasq.conf.default EXPOSE 8080 EXPOSE 53 ENTRYPOINT ["/docker-entrypoint.sh"]
docker-entrypoint.sh 编写
vim docker-entrypoint.sh
#!/bin/bash systemctl start dnsmasq webproc -c /etc/dnsmasq.conf -c /etc/hosts -- dnsmasq --no-daemon
编译镜像
vim build.sh
#!/bin/bash docker build -t dnsmasq:latest .
编译
sh build.sh
docker-compose.yml 编写
vim docker-compose.yml
version: '3' networks: app-tier: driver: bridge services: etcd: image: 'dnsmasq:latest' container_name: "dns" restart: always ports: - 8080:8080 - 53:53/tcp - 53:53/udp volumes: - /etc/hosts:/etc/hosts - /data/docker_volumes/dns/dnsmasq.conf:/etc/dnsmasq.conf - /data/docker_volumes/dns/logs/dnsmasq.log:/va/log/dnsmasq.log - /etc/resolv.conf:/etc/resolv.conf networks: - app-tier
挂载路径创建
创建挂载
mkdir -p /data/docker_volumes/dns/logs && touch /data/docker_volumes/dns/logs/dnsmasq.log
创建 dnsmasq.conf
vim /data/docker_volumes/dns/dnsmasq.conf
尾部写入:
# Include all files in /etc/dnsmasq.d except RPM backup files conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig # dns log log-facility=/va/log/dnsmasq.log
完整内容查看:dnsmasq.conf
运行镜像
docker-compose up -d
查看
浏览器输入: ip:8080
客户端配置
在需要域名访问的机器上配置 DNS
地址,dns 地址为你搭建 dnsmasq
服务的地址。
以下为例子:
windows
centOS
macOS
域名访问
配置完成后即可按照你配置的域名进行访问,如上例,可以在浏览器输入 : myweb.com
访问网站。
到此这篇关于docker搭建dnsmasq服务的实现的文章就介绍到这了,更多相关docker搭建dnsmasq服务内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!