当系统启动的时候要启动docker container, 可以利用systemctl来实现
比如拿mongodb为例
- 创建 /usr/lib/systemd/system/docker_mongodb.service
[Unit]
Description=mongodb container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a mongodb_01
ExecStop=/usr/bin/docker stop -t 2 mongodb_01
[Install]
WantedBy=default.target
- systemctl enable docker_mongodb