在centos7上将通过yum安装的docker-ce-23.0.1 注册为系统服务
时间: 2024-05-03 19:21:18 浏览: 83
可以按照以下步骤在CentOS 7上将Docker CE 23.0.1注册为系统服务:
1. 首先,使用以下命令安装Docker CE 23.0.1:
```
sudo yum install docker-ce-23.0.1
```
2. 然后,创建一个新的systemd服务文件来启动Docker CE。使用以下命令打开一个新文件:
```
sudo nano /etc/systemd/system/docker.service
```
3. 将以下内容复制并粘贴到该文件中:
```
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket
[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
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 later, 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.
StartLimitInterval=60s
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
[Install]
WantedBy=multi-user.target
```
4. 保存和关闭该文件。
5. 开启新的systemd服务并使其自动启动:
```
sudo systemctl daemon-reload
sudo systemctl enable docker
sudo systemctl start docker
```
6. 确认服务已成功启动:
```
sudo systemctl status docker
```
如果服务已成功启动,则会显示Active(运行中)状态。
阅读全文