说明
本服务包含:
dns-web-ui: webproc
dns-service: 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
配置解析地址
进入宿主机
器执行:
vim /etc/hosts
ip 域名
# 例如:
172.13.20.89 myweb.com
运行镜像
docker-compose up -d
查看
浏览器输入:
ip:8080
显示如下:
客户端配置
在需要域名访问的机器上配置 DNS
地址,dns 地址为你搭建 dnsmasq
服务的地址。
以下为例子:
windows
linux
macOS
域名访问
配置完成后即可按照你配置的域名进行访问,如上例,可以在浏览器输入 : myweb.com
访问网站。