Docker compose在Centos设置开机启动
2024-10-22 14:52:45

Docker compose在Centos设置开机启动

配置文件

假设你的服务器已经安装好了dockerdocker compose,若想进行开机启动。则需要用到systemctl

将下面内容保存到/etc/systemd/system/myblog.service文件

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=My Blog Project
Requires=docker.service
After=docker.service

[Service]
Type=simple
ExecStart=/bin/bash -c "docker compose -f /www/docker-compose.yml up"
ExecStop=/bin/bash -c "docker compose -f /www/docker-compose.yml stop"

[Install]
WantedBy=multi-user.target

重启实例

1
systemctl daemon-reload

设置开机启动

1
systemctl enable myblog.service

立即启动

1
systemctl start myblog.service