0、准备工作

如果是全新安装的服务器,先要给root账户设置密码,命令是

sudo passwd root

然后切换到root账户

su root

上述过程屏幕输出如下

1、Docker-Compose的配置文件

用vi编辑器,创建文件:

vi docker-compose.yml

内容如下:

version: '3.6'

networks:
main:
ipam:
config:
- subnet: 10.10.1.0/24 services:
web:
image: 'sameersbn/bind:9.16.1-20200524'
container_name: dns
restart: always
networks:
main:
ipv4_address: 10.10.1.2
ports:
- '53:53/udp'
- '10000:10000/tcp'
volumes:
- '/mnt/data/dns-server:/data'
shm_size: '256m'

保存后退出

2、用docker-compose启动容器

- 可能提示没有安装docker-compose

root@dns-server:/home/public/software/dns# docker-compose up -d
Command 'docker-compose' not found, but can be installed with:
snap install docker # version 20.10.24, or
apt install docker-compose # version 1.29.2-1
See 'snap info docker' for additional versions.

- 遵照上一步的提示,安装docker-compose

root@dns-server:/home/public/software/dns# apt install docker-compose
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
bridge-utils containerd dns-root-data dnsmasq-base docker.io pigz python3-docker python3-dockerpty python3-docopt python3-dotenv python3-texttable python3-websocket runc ubuntu-fan
Suggested packages:
ifupdown aufs-tools cgroupfs-mount | cgroup-lite debootstrap docker-doc rinse zfs-fuse | zfsutils
The following NEW packages will be installed:
bridge-utils containerd dns-root-data dnsmasq-base docker-compose docker.io pigz python3-docker python3-dockerpty python3-docopt python3-dotenv python3-texttable python3-websocket runc ubuntu-fan
0 upgraded, 15 newly installed, 0 to remove and 60 not upgraded.
Need to get 72.7 MB of archives.
After this operation, 288 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 bridge-utils amd64 1.7-1ubuntu3 [34.4 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 runc amd64 1.1.4-0ubuntu1~22.04.3 [4,244 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 containerd amd64 1.6.12-0ubuntu1~22.04.3 [34.4 MB]
Get:5 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 dns-root-data all 2021011101 [5,256 B]
Get:6 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 dnsmasq-base amd64 2.86-1.1ubuntu0.3 [354 kB]
Get:7 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-websocket all 1.2.3-1 [34.7 kB]
Get:8 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-docker all 5.0.3-1 [89.3 kB]
Get:9 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-dockerpty all 0.4.1-2 [11.1 kB]
Get:10 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-docopt all 0.6.2-4 [26.9 kB]
Get:11 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-dotenv all 0.19.2-1 [20.5 kB]
Get:12 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-texttable all 1.6.4-1 [11.4 kB]
Get:13 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 docker-compose all 1.29.2-1 [95.8 kB]
Get:14 http://cn.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 docker.io amd64 20.10.21-0ubuntu1~22.04.3 [33.3 MB]
Get:15 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 ubuntu-fan all 0.12.16 [35.2 kB]
Fetched 72.7 MB in 20s (3,598 kB/s)
Preconfiguring packages ...
Selecting previously unselected package pigz.
(Reading database ... 74075 files and directories currently installed.)
Preparing to unpack .../00-pigz_2.6-1_amd64.deb ...
Unpacking pigz (2.6-1) ...
Selecting previously unselected package bridge-utils.
Preparing to unpack .../01-bridge-utils_1.7-1ubuntu3_amd64.deb ...
Unpacking bridge-utils (1.7-1ubuntu3) ...
Selecting previously unselected package runc.
Preparing to unpack .../02-runc_1.1.4-0ubuntu1~22.04.3_amd64.deb ...
Unpacking runc (1.1.4-0ubuntu1~22.04.3) ...
Selecting previously unselected package containerd.
Preparing to unpack .../03-containerd_1.6.12-0ubuntu1~22.04.3_amd64.deb ...
Unpacking containerd (1.6.12-0ubuntu1~22.04.3) ...
Selecting previously unselected package dns-root-data.
Preparing to unpack .../04-dns-root-data_2021011101_all.deb ...
Unpacking dns-root-data (2021011101) ...
Selecting previously unselected package dnsmasq-base.
Preparing to unpack .../05-dnsmasq-base_2.86-1.1ubuntu0.3_amd64.deb ...
Unpacking dnsmasq-base (2.86-1.1ubuntu0.3) ...
Selecting previously unselected package python3-websocket.
Preparing to unpack .../06-python3-websocket_1.2.3-1_all.deb ...
Unpacking python3-websocket (1.2.3-1) ...
Selecting previously unselected package python3-docker.
Preparing to unpack .../07-python3-docker_5.0.3-1_all.deb ...
Unpacking python3-docker (5.0.3-1) ...
Selecting previously unselected package python3-dockerpty.
Preparing to unpack .../08-python3-dockerpty_0.4.1-2_all.deb ...
Unpacking python3-dockerpty (0.4.1-2) ...
Selecting previously unselected package python3-docopt.
Preparing to unpack .../09-python3-docopt_0.6.2-4_all.deb ...
Unpacking python3-docopt (0.6.2-4) ...
Selecting previously unselected package python3-dotenv.
Preparing to unpack .../10-python3-dotenv_0.19.2-1_all.deb ...
Unpacking python3-dotenv (0.19.2-1) ...
Selecting previously unselected package python3-texttable.
Preparing to unpack .../11-python3-texttable_1.6.4-1_all.deb ...
Unpacking python3-texttable (1.6.4-1) ...
Selecting previously unselected package docker-compose.
Preparing to unpack .../12-docker-compose_1.29.2-1_all.deb ...
Unpacking docker-compose (1.29.2-1) ...
Selecting previously unselected package docker.io.
Preparing to unpack .../13-docker.io_20.10.21-0ubuntu1~22.04.3_amd64.deb ...
Unpacking docker.io (20.10.21-0ubuntu1~22.04.3) ...
Selecting previously unselected package ubuntu-fan.
Preparing to unpack .../14-ubuntu-fan_0.12.16_all.deb ...
Unpacking ubuntu-fan (0.12.16) ...
Setting up python3-dotenv (0.19.2-1) ...
Setting up python3-texttable (1.6.4-1) ...
Setting up python3-docopt (0.6.2-4) ...
Setting up dnsmasq-base (2.86-1.1ubuntu0.3) ...
Setting up runc (1.1.4-0ubuntu1~22.04.3) ...
Setting up dns-root-data (2021011101) ...
Setting up bridge-utils (1.7-1ubuntu3) ...
Setting up pigz (2.6-1) ...
Setting up containerd (1.6.12-0ubuntu1~22.04.3) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up python3-websocket (1.2.3-1) ...
Setting up python3-dockerpty (0.4.1-2) ...
Setting up ubuntu-fan (0.12.16) ...
Created symlink /etc/systemd/system/multi-user.target.wants/ubuntu-fan.service → /lib/systemd/system/ubuntu-fan.service.
Setting up python3-docker (5.0.3-1) ...
Setting up docker.io (20.10.21-0ubuntu1~22.04.3) ...
Adding group `docker' (GID 120) ...
Done.
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Setting up docker-compose (1.29.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images... Running kernel seems to be up-to-date. The processor microcode seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@dns-server:/home/public/software/dns#

- 再次用docker-compose启动容器

会发现linux系统已经能执行docker-compose命令,但是最终是报错。

root@ami-home-gateway:/home/david/software/dns# ls
docker-compose.yml
root@ami-home-gateway:/home/david/software/dns# docker-compose up -d
/snap/docker/2285/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography.hazmat.backends import default_backend
Creating network "dns_main" with the default driver
Pulling web (sameersbn/bind:9.16.1-20200524)...
9.16.1-20200524: Pulling from sameersbn/bind
d51af753c3d3: Pull complete
fc878cd0a91c: Pull complete
6154df8ff988: Pull complete
fee5db0ff82f: Pull complete
7d5f2b88fbe1: Pull complete
677da372f47f: Pull complete
4adaef8a17ca: Pull complete
00abb6dce6f7: Pull complete
d7852cfdd714: Pull complete
Digest: sha256:685d9404bf08c177413a7448bfdb7ae71ee002a3fbf917fd8d46d4aadd687522
Status: Downloaded newer image for sameersbn/bind:9.16.1-20200524
Creating dns ...
Creating dns ... error ERROR: for dns Cannot start service web: driver failed programming external connectivity on endpoint dns (7113503da0649c0f745f4a53c16c3c1de24b767f6fbbf816747bf04d987fe803): Error starting userland proxy: listen udp4 0.0.0.0:53: bind: address already in use ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint dns (7113503da0649c0f745f4a53c16c3c1de24b767f6fbbf816747bf04d987fe803): Error starting userland proxy: listen udp4 0.0.0.0:53: bind: address already in use
ERROR: Encountered errors while bringing up the project.

上边提示的很清楚,因为DNS需要的UDP53端口,被Ubuntu占用了,

3、修改物理服务器

目的是释放对UDP端口53的占用,让容器启动后能使用UDP53端口。

修改/etc/systemd/resolved.conf文件

root@amicore:~# cd /etc/systemd/
root@amicore:/etc/systemd# ls
journald.conf logind.conf network networkd.conf pstore.conf resolved.conf sleep.conf system system.conf timesyncd.conf user user.conf
root@amicore:/etc/systemd# vi resolved.conf

文件修改两个地方

#  This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the resolved.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
#
# See resolved.conf(5) for details. [Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
# Google: 8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
# Quad9: 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
# 第一个改动,把这里的IP地址改成服务器在局域网中的地址
DNS=192.168.3.254
#FallbackDNS=
#Domains=
#DNSSEC=no
#DNSOverTLS=no
#MulticastDNS=no
#LLMNR=no
#Cache=no-negative
#CacheFromLocalhost=no
# 第二个改动,把#号去掉,yes改成no
DNSStubListener=no
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no

我没有确认是否生效,保存上述修改后,直接尝试用docker-compose启动容器,继续报错如下:

root@dev-server:/home/public/software/dns# docker-compose up -d
Starting dns ...
Starting dns ... error ERROR: for dns Cannot start service web: driver failed programming external connectivity on endpoint dns (9739bf23d700a34dd297df89693e5978670464d74a991881e0522d69c1aa6a26): Error starting userland proxy: listen udp4 0.0.0.0:53: bind: address already in use ERROR: for web Cannot start service web: driver failed programming external connectivity on endpoint dns (9739bf23d700a34dd297df89693e5978670464d74a991881e0522d69c1aa6a26): Error starting userland proxy: listen udp4 0.0.0.0:53: bind: address already in use
ERROR: Encountered errors while bringing up the project.
root@dev-server:/home/public/software/dns#

用reboot命令重新启动服务器,再尝试启动容器,成功了:

root@dev-server:/home/public/software/dns# docker-compose up -d

Starting dns ... done

4、再次改动服务器

如果容器无法被启动(安装),那么进入下述步骤

查看下述文件的内容。

root@amicore:/etc/systemd# cd /etc
root@amicore:/etc# vi resolv.conf

### 文件内容如下

# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf. nameserver 192.168.3.1
search .

nameserver只有192.168.3.1证明没有生效,得修改

root@amicore:/etc# rm -f resolv.conf
root@amicore:/etc# sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

再次查看,竟然还是没有生效,reboot服务器吧!

生效后文件内容如下

# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf. nameserver 192.168.3.254
nameserver 192.168.3.1
search .

5、再次用docker-compose启动容器

先前的安装是失败了的,重新运行

docker-compose up -d

发现成功了

root@dev-server:/home/public/software/dns# docker-compose up -d
Starting dns ... done

下一篇文章我们将如何配置DNS服务器。

用Docker搭建DNS服务器的更多相关文章

  1. 通过Docker配置DNS服务器

    1. 概述 DockerHub中的 sameersbn/bind 镜像提供了搭建DNS服务器的功能,本文给出使用该镜像搭建DNS服务器的例子. 2. 环境 DNS服务器主机 IP:10.11.150. ...

  2. 第一次搭建dns服务器

    CentOS 7 搭建DNS服务器 主要参考的是小左先森的一篇博客:https://blog.51cto.com/13525470/2054121. 1.搭建过程中遇到的几个问题说一下: a.在重启服 ...

  3. centos DNS服务搭建 DNS原理 使用bind搭建DNS服务器 配置DNS转发 配置主从 安装dig工具 DHCP dhclient 各种域名解析记录 mydns DNS动态更新 第三十节课

    centos  DNS服务搭建  DNS原理  使用bind搭建DNS服务器 配置DNS转发 配置主从  安装dig工具  DHCP  dhclient  各种域名解析记录  mydns DNS动态更 ...

  4. [转]DNS服务器原理详解与Centos6.x下搭建DNS服务器

    转自:http://blog.it985.com/8958.html DNS 数据库的记录:正解,反解, Zone 的意义 通过DNS解析过程详解这篇文章,我们知道了要想访问www.zmit.cn,最 ...

  5. Centos7 搭建DNS服务器与原理配置详解

    在搭建我们自己DNS服务器之前,先必须了解下DNS服务器的作用和原理. DNS是在互联网上进行域名解析到对应IP地址的服务器,保存互联网上所有的IP与域名的对应信息,然后将我们对网址的访问,解析成IP ...

  6. Windows Server 2008 R2 搭建DNS服务器(转)

    Windows Server 2008 R2 搭建DNS服务器将本机IP设为首选DNS服务器的地址在dos 下分别输入 nslookup www.mydns.com 和 nslookup 192.16 ...

  7. centos搭建dns服务器

    前言:搭建dns服务器,dns服务器我就不多说什么了,大家都懂,就是域名解析,就将ip装换为域名,域名就可以理解为类似这样的www.baidu.com网址,接下来我就直接上图了.这里面最重要的是修改u ...

  8. Docker搭建Svn服务器

    一.下载镜像 # 搜索镜像 docker search svn # 下载镜像 docker pull garethflowers/svn-server 二.启动镜像 # 编辑配置文件 vim dock ...

  9. 快速搭建 DNS 服务器: skydns + etcd

    参考: [ skynetservice github ] [ skydns 测试记录 CSDN ] etcd 安装配置 安装 yum install etcd 配置 sed -i 's@ETCD_LI ...

  10. Linux系统下搭建DNS服务器——DNS原理总结

    2017-01-07 整理 DNS原理 域名到IP地址的解析过程 IP地址到域名的反向域名解析过程 抓包分析DNS报文和具体解析过程 DNS服务器搭建和配置 这个东东也是今年博主参见校招的时候被很多公 ...

随机推荐

  1. Rendezvous hashing算法介绍

    Rendezvous hashing Rendezvous hashing用于解决分布式系统中的分布式哈希问题,该问题包括三部分: Keys:数据或负载的唯一标识 Values:消耗资源的数据或负载 ...

  2. 一文带你搞懂如何优化慢SQL

    作者:京东科技 宋慧超 一.前言 最近通过SGM监控发现有两个SQL的执行时间占该任务总执行时间的90%,通过对该SQL进行分析和优化的过程中,又重新对SQL语句的执行顺序和SQL语句的执行计划进行了 ...

  3. Redis极简教程

    简介 Redis 是用C语言开发完全开源免费的,遵守BSD协议的,一个高性能的,key-value型的,NOSQL数据库. 特点 可以将内存中的数据持久化到硬盘中,重启的时候可以从硬盘中再次加载 拥有 ...

  4. bug的分类

    bug的分类 语法上的问题: 在循环的时候, 1.一定要注意这个循环的对象是否是空对象:空对象就不需要进行循环了, 判断一下,空对象就不需要进行循环了: 2.在XXX.a属性的时候,要注意这个对象是否 ...

  5. vm-storage在新metric占整体1%情况下的写入性能测试

    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 根据正式环境实际的数据统计,全新的metric占整体的me ...

  6. C/C++ Qt 基本文件读写方法

    Qt文件操作有两种方式,第一种使用QFile类的IODevice读写功能直接读写,第二种是利用 QFile和QTextStream结合起来,用流的方式进行文件读写. 第一种,利用QFile中的相关函数 ...

  7. STM32CubeMX教程28 SDIO - 使用FatFs文件系统读写SD卡

    1.准备材料 正点原子stm32f407探索者开发板V2.4 STM32CubeMX软件(Version 6.10.0) keil µVision5 IDE(MDK-Arm) ST-LINK/V2驱动 ...

  8. 使用window.print进行前端打印,批量打印,设置分页,ie、火狐下设置页眉页脚

    window.print() print() 方法用于打印当前窗口的内容.谷歌调用 print() 方法会产生一个打印预览弹框,让用户可以设置打印请求. 但谷歌貌似不能自定义设置页眉页脚的文字:ie和 ...

  9. MindSpore导入CUDA算子

    技术背景 当今众多的基于Python的AI框架(如MindSpore.PyTorch等)给了开发者非常便利的编程的条件,我们可以用Python的简单的语法写代码,然后由框架在后端自动编译成可以在GPU ...

  10. 麒麟V10虚拟机安装(详细)

    现在国企和央企单位都在做国产化适配工作,服务器采用:中科曙光(海光Hygon).中科德泰(龙芯Loongson).宝德(鲲鹏Kunpeng)等国产配备国产处理器的服务器:数据库采用:人大金仓(King ...