docker生成ssl证书(按步骤来即可,真实可用)

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昨夜剑客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值