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、修改物理服务器
修改/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
确认一下是否生效了?
重新启动服务器后:
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 .
4、再次用docker-compose启动容器
先前的安装是失败了的,重新运行
docker-compose up -d
发现成功了
标签:Dockers,...,dns,conf,DNS,ubuntu,服务器,docker,python3 From: https://www.cnblogs.com/amisoft/p/17537369.html