首页 文章

启动systemd脚本后重启后,Docker容器无法启动

提问于
浏览
1

我有以下systemd脚本:

[Unit]
Description=Hub docker container
After=docker.service

[Service]
User=root
ExecStart=/home/hub/hub.sh
ExecStop=/bin/docker stop hub
ExecStopPost=/bin/docker rm hub

[Install]
WantedBy=multi-user.target

运行命令: systemctl start/stop hub 工作正常 . 我还使用 systemctl enable hub 创建了符号链接 . 为什么没有't my service start up after I reboot the entire laptop? I followed the docker guide so that Docker starts up on reboot, but for some reason my container doesn'启动 . 我在脚本中遗漏了一个字段吗?

我正在使用我的ExecStart命令“/home/hub/hub.sh”脚本是:

docker run --net=host --restart=always --name hub -t hub

重新启动后,当我输入systemctl status hub时,我得到以下信息:

● hub.service - Hub docker container
   Loaded: loaded (/etc/systemd/system/hub.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

1 回答

  • 0

    要在重新启动后启动容器,您需要将此属性: --restart=always 添加到容器启动脚本中 . 例如: docker run -d -p 80:5000 --restart=always image_name

相关问题