dockerd启动配置_修改IP和systemd管理

docker采用CS架构,dockerd是管理后台进程,默认的配置文件为/etc/docker/daemon.json(--config-file可以指定非默认位置)。

一个完整的daemon.json示例参考:https://docs.docker.com/engine/reference/commandline/dockerd//#daemon-configuration-file

通过此文件可修改docker0的默认IP及bridge(Customize the docker0 bridge):

{
  "bip": "192.168.1.5/24",
  "fixed-cidr": "192.168.1.5/25",
  "fixed-cidr-v6": "2001:db8::/64",
  "mtu": 1500,
  "default-gateway": "10.20.1.1",
  "default-gateway-v6": "2001:db8:abcd::89",
  "dns": ["10.20.1.2","10.20.1.3"]
}

几乎可以通过daemon.json配置所有docker daemon特性, 除了HTTP proxy

HTTP/HTTPS proxy

The Docker daemon uses the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environmental variables in its start-up environment to configure HTTP or HTTPS proxy behavior. You cannot configure these environment variables using the daemon.json file.

Proxy相关配置参考:https://docs.docker.com/config/daemon/systemd/

systemd管理

一般dockerd启动采用systemd管理:

[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

其中-H fd://如何理解呢?

When you start the Docker daemon, -H fd:// will tell Docker that the service is being started by Systemd and will use socket activation. systemd will then create the target socket and pass it to the Docker daemon to use. This is described in introduction to Systemd and in introduction to socket activation. The blogs are pretty long but really worth reading, here‘s a short summary of key points for understanding this question:

  • Systemd is a new init system intended to replace traditional SysV init system. One of its key features is faster init process.
  • Socket activation is one of the technologies used in Systemd to speed up service initialization
  • To receive requests, the service needs a socket to listen on. Take Docker as an example, it needs a unix domain socket like /var/run/docker.sock or a TCP socket. Of course these sockets needs something to create them and most of the time it is the service itself at start time.
  • With socket activation, SystemD will create these sockets and listen to them for services, and pass these sockets to service with exec when the service is started. One benefit is that client requests can be queued in the socket buffer once the socket is successfully created, even before the related service is started.
  • The socket info for a certain service used by Systemd is in socket unit file, for Docker it‘s [docker.socket][3] with content:
[Unit]
Description=Docker Socket for the API
PartOf=docker.service

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

Let‘s see how the whole thing works. I have the files docker.socket and docker.service under /etc/systemd/system. The ExecStart line for docker.service is:

ExecStart=/usr/bin/dockerd -H fd://

1)Stop Docker service: systemctl stop docker

$> ps aux | grep ‘docker‘ # the `grep` itself in the output is ignored
$> lsof -Ua | grep ‘docker‘
$>

No docker process is running, and no docker.sock

2)Execute systemctl start docker.socket:

$> systemctl start docker.socket
$> ps aux | grep ‘docker‘
$> lsof -Ua | grep ‘docker‘
systemd       1    root   27u  unix 0xffff880036da6000      0t0 140748188 /var/run/docker.sock

After start docker.socket, we can see that there‘s still no docker process running, but the socket /var/run/docker.sock has been created, and it belongs to the process systemd.

(Off-Topic: Actually the socket is ready to receive requests now, even though docker is not running yet. systemd will start docker.service at the moment the first request comes, passing the already created sockets to Docker. This is so-called on-demand auto-spawning)

3)Start docker.service

$> systemctl start docker.service
$> ps aux | grep ‘docker‘
root     26302  0.0  1.8 431036 38712 ?        Ssl  14:57   0:00 /usr/bin/dockerd -H fd://
<....>

As you can tell Docker is now running. Let‘s go one step back and try to execute /usr/bin/dockerd -H fd:// manually from terminal:

$> /usr/bin/dockerd -H fd://
FATA[0000] no sockets found via socket activation: make sure the service was started by systemd

Now you see the difference; when you use -H fd://, docker will expect the socket to be passed by its parent process rather than creating it by itself. When it‘s started by Systemd, Systemd will do the job, but when you manually start it on terminal, you don‘t do the job so the docker daemon process failed and aborted. This is the code of how docker process fd:// when docker daemon starts, you can have a look if you‘re interested.

参考:

1. https://stackoverflow.com/questions/43303507/what-does-fd-mean-exactly-in-dockerd-h-fd

2. https://docs.docker.com/engine/reference/commandline/dockerd//#daemon-configuration-file

3. https://docs.docker.com/config/daemon/systemd/

4.  Docker 如何自定义默认网桥 docker0

原文地址:https://www.cnblogs.com/embedded-linux/p/10776764.html

时间: 2024-10-14 01:00:02

dockerd启动配置_修改IP和systemd管理的相关文章

Ubuntu配置和修改IP地址

1.修改配置文件/etc/network/interfaces[email protected]:~# sudo gedit /etc/network/interfaces 添加以下内容:auto eth0                  #设置自动启动eth0接口iface eth0 inet static     #配置静态IPaddress 192.168.11.88      #IP地址netmask 255.255.255.0      #子网掩码gateway 192.168.11

安装配置好openstack环境的虚拟机,需要修改ip时,在数据库中同步修改ip的方法

由于配置openstack 环境的时候,创建了很多表,都配置了本机的ip 所以当本机需要修改ip的 时候  就需要同步数据库中所有与环境有关的ip 方法: 1.进入数据库 [[email protected] Desktop]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 2 Server vers

修改Docker容器启动配置参数

有时候,我们创建容器时忘了添加参数 --restart=always ,当 Docker 重启时,容器未能自动启动, 现在要添加该参数怎么办呢,方法有二: 1.Docker 命令修改 docker container update --restart=always 容器名字 2.直接改配置文件 首先停止容器,不然无法修改配置文件 配置文件路径为:/var/lib/docker/containers/容器ID 在该目录下找到一个文件 hostconfig.json ,找到该文件中关键字 Resta

【Linux】Jenkins以war包运行及开机启动配置(四)

本例介绍jenkins已war包运行及开机启动配置 环境:Linux环境(CentOS 7.4) 以war包运行 1.下载jenkins.war包 2.启动war包( 默认端口:8080,默认JENKINS_HOME目录:-/.jenkins ) 前台启动命令:java -jar jenkins.war 后台启动命令:nohup java -jar jenkins.war & 3.使用浏览器打开地址:http://ip:8080,即可访问到jenkins 关闭jenkins,页面访问地址:htt

Linux系统下修改IP地址、网关、DNS的基本方法

临时修改IP地址.网关.主机名.DNS,马上生效,无需重启(重启后失效) 1.修改主机名 #hostname Slyar 2.修改IP地址(eth0为网卡名称) #ifconfig eth0 192.168.1.5 netmask 255.255.255.0 3.修改默认网关(eth0为网卡名称) #route add default gw 192.168.1.1 dev eth0 4.修改DNS #vim /etc/resolv.conf CentOS(RedHat)命令行永久修改IP地址.网

【学神-RHEL7】1-23-RHEL7启动配置

本节所讲内容: RHEL7 启动配置   MBR保存着系统的主引导程序(grub 446字节,分区表64字节),启动过程就是把内核加载到内存.   启动的顺序: 1.BIOS: 2.BIOS激活MBR: 3.MBR中的引导程序(grub)加载到内存,生成一个微系统(如xfs): 4.grub 读取分区表,找到引导分区: 5.grub读取自身的配置文件,找到内核文件 6.加载内核文件:   RHEL7中第一个启动进程不在init进程 [[email protected] ~]#pstree -p

MongoDB启动配置等

目录: 一.mongoDB 启动配置 二.导出,导入,运行时备份 三.Fsync锁,数据修复 四.用户管理,安全认证 一.启动项 mongod --help C:\Windows\system32>mongod --help 1.常用配置项 --dbpath 指定数据库的目录,默认在window下是c:\data\db\ --port 指定服务器监听的端口号码,默认是27017 --fork 用守护进程的方式启动mongoDB --logpath 指定日志的输出路径,默认是控制台 --confi

配置linux的ip、网络等

之前配过ubuntu的..以为centos的也是这么配置,结果照抄下来,启动报错哈哈...网上搜下资料发现centos配置需要不少文件.忘了以后再参考下 ubuntu的,这样配置 centos的配置就需要在多个文件里设置内容,而且参数变量后边需要等号“=”,这个不同于ubuntu,    参考http://www.21andy.com/new/20100227/1717.html 一.CentOS 修改IP地址 修改对应网卡的IP地址的配置文件# vi /etc/sysconfig/networ

[转载]CentOS 修改IP地址, DNS, 网关

一.CentOS 修改IP地址 修改对应网卡的IP地址的配置文件 # vi /etc/sysconfig/network-scripts/ifcfg-eth0   电信 # vi /etc/sysconfig/network-scripts/ifcfg-eth0:1 网通 修改以下内容DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0BOOTPROTO=static #设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应