ps:ip:xxxx 代表输入ip,ip字样不写
建议小伙伴多敲一敲
1、mkdir -pv /etc/docker/certs
2 、cd /etc/docker/certs
3、 openssl genrsa -aes256 -out ca-key.pem 4096(生成一个key)
Enter pass phrase for ca-key.pem: # 此处输入你想设置的密码
Verifying - Enter pass phrase for ca-key.pem: # 再次输入
4 、openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
Enter pass phrase for ca-key.pem: # 此处输入你想设置的密码
Verifying - Enter pass phrase for ca-key.pem: # 再次输入
5 、openssl genrsa -out server-key.pem 4096
Enter pass phrase for ca-key.pem: # 此处输入你想设置的密码
Verifying - Enter pass phrase for ca-key.pem: # 再次输入
6、 openssl req -subj "/CN=ip:xxxx" -sha256 -new -key server-key.pem -out server.csr
Enter pass phrase for ca-key.pem: # 此处输入你想设置的密码
Verifying - Enter pass phrase for ca-key.pem: # 再次输入
7、 echo subjectAltName = IP:0.0.0.0,IP:xxxx,IP:127.0.0.1 >> extfile.cnf
8、 echo extendedKeyUsage = serverAuth >> extfile.cnf
9、 openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem -extfile extfile.cnf
10、 openssl genrsa -out key.pem 4096
11 、openssl req -subj "/CN=ip:xxxx" -new -key key.pem -out client.csr
12、 echo extendedKeyUsage = clientAuth > extfile-client.cnf
13、 openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out cert.pem -extfile extfile-client.cnf
14、 rm -v client.csr server.csr extfile.cnf extfile-client.cnf
15、 y
16、 chmod -v 0400 ca-key.pem key.pem server-key.pem
17、 chmod -v 0444 ca.pem server-cert.pem cert.pem
18 、vi /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 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 --tlsverify --tlscacert=/etc/docker/certs/ca.pem --tlscert=/etc/docker/certs/server-cert.pem --tlskey=/etc/docker/certs/server-key.pem -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.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
OOMScoreAdjust=-500[Install]
WantedBy=multi-user.target
19、 cat /lib/systemd/system/docker.service
20、 systemctl daemon-reload
21、 systemctl restart docker