AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1058229
Accepted
Rody Oldenhuis
Rody Oldenhuis
Asked: 2021-03-25 18:14:52 +0800 CST2021-03-25 18:14:52 +0800 CST 2021-03-25 18:14:52 +0800 CST

Docker 守护进程在启动时忽略 daemon.json

  • 772

我的 Docker 守护进程似乎/etc/docker/daemon.json在启动时忽略了。

与这个问题类似,我在告诉 Docker 守护进程它不应该使用默认172.17.*范围时遇到了一些麻烦。该范围已被我们的 VPN 占用,并阻止通过该 VPN 连接的人员连接到运行 Docker 的服务器。

非常烦人的事情是,每次我重新启动服务器时,Docker 都会再次从 VPN 的范围内申请一个 IP,而不管我输入了什么/etc/docker/daemon.json。我必须手动发出

# systemctl restart docker

启动后直接在172.17.*网络上的人可以再次访问服务器之前。

这显然经常被遗忘,并导致许多问题票。

我的/etc/docker/daemon.json样子是这样的:

{
 "default-address-pools": [
   {
      "base": "172.20.0.0/16",
      "size": 24
   }
 ]
}

并获得这样的许可:

-rw-r--r--   1 root root   123 Dec  8 10:43 daemon.json

我什至不知道如何开始诊断这个问题;有任何想法吗?

为了完整性:

  • Ubuntu 18.04.5 LTS
  • Docker 版本 19.03.6,构建 369ce74a3c

编辑:输出systemctl cat docker:

# /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
Wants=containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

sudo docker info(之后systemctl restart docker)的输出:

Client:
 Debug Mode: false

Server:
 Containers: 34
  Running: 19
  Paused: 0
  Stopped: 15
 Images: 589
 Server Version: 19.03.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-140-generic
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 47.16GiB
 Name: linuxsrv
 ID: <redacted>
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: <redacted>
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  http://172.16.30.33:6000/
 Live Restore Enabled: false

WARNING: No swap limit support
ubuntu boot daemon docker
  • 2 2 个回答
  • 2025 Views

2 个回答

  • Voted
  1. Best Answer
    BMitch
    2021-04-08T05:49:33+08:002021-04-08T05:49:33+08:00

    docker 使用了多个地址池。default-address-pools适用于所有新用户创建的桥接网络。更改此设置后,您可能需要删除并重新创建这些网络。

    还有bip, 在daemon.json文件中设置如下行:

    "bip": "192.168.63.1/24"
    

    该bip设置适用于名为的默认桥接网络bridge,并且需要设置为该桥接网络上网关的 CIDR(因此您不能将其定义为192.168.63.0/24,尾随.1很重要)。

    如果您使用的是 swarm 模式,则覆盖网络有自己的地址池,在覆盖网络中的节点之间共享。这需要在docker swarm init使用--default-addr-pool标志期间进行配置。

    最后,如果您通过 snap 运行 docker,此文件的位置是/var/snap/docker/current/etc/docker/daemon.json并且不会出现在更新中保留,因此您需要在更新后再次替换此文件。

    • 1
  2. Rody Oldenhuis
    2021-04-21T01:14:21+08:002021-04-21T01:14:21+08:00

    虽然我认为我使用 BMitch 的答案解决了问题,但我错了 -引导后docker0地址仍然在错误的范围内。172.17.*.*

    经过更多的挖掘,结果发现,不知何故,我dockerd安装了多个版本:

    1. 如果您按照文档安装,您会得到一个
    2. ...通过 Snap 安装的那个?‍♂️

    显然,来自 Snap 的那个是启动时启动的,而另一个是运行时启动的sudo systemctl restart docker。

    从 Snap 中卸载并清除逃脱(...逃避?)我的注意力终于解决了这个讨厌的问题。

    • 1

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve