方式一
1. vim /etc/rc.d/rc.local
2. 添加启动命令
3. chmod u+x /etc/rc.d/rc.local
方式二
1. cd /etc/rc.d/init.d/
2. touch xxx.sh && chmod u+x xxx.sh
3. vim xxx.sh
4. 添加如下内容
#!/bin/bash
# chkconfig: 2345 85 15
# description: docker-compose
具体的启动命令
方式三
1. cd /etc/systemd/system/
2. touch xxxx.service
3. vim xxxx.service
4. 添加如下内容
[Unit]
Description=docker compose service
After=docker.service
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/docker-compose -f /usr/workspace/harbor/docker-compose.yml up -d
ExecStop=/usr/local/bin/docker-compose down
Restart=always
[Install]
WantedBy=multi-user.target
5. systemctl daemon-reload
6. systemctl enable xxxx.service
7. systemctl start xxxx.service