我有一个 docker-compose 项目,我想通过 systemd 进行控制。我在 systemd 中有下一个文件。
[Unit]
Description=My Server container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f /home/adminuser/project/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /home/adminuser/project/docker-compose.yml stop
[Install]
WantedBy=multi-user.target
我已经在 Amazon Web Services 中的实例中成功测试了此文件。每次我重新启动时,我的服务都会运行,但实际上我需要在安装了 Ubuntu Server 16.04 的 Server hp proliant microserver gen8 中实现该服务,不幸的是,当我重新启动服务器时,该服务无法启动我的 docker 项目。
这是显示错误。
● backend.project.service - My Server container
Loaded: loaded (/etc/systemd/system/backend.sssirsa.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since mar 2016-11-15 09:38:26 CST; 1h 17min ago
Process: 3469 ExecStop=/usr/local/bin/docker-compose -f /home/adminuser/project/docker-compose.yml stop (code=exited, status=1/FAILURE)
Process: 3461 ExecStart=/usr/local/bin/docker-compose -f /home/adminuser/project/docker-compose.yml up (code=exited, status=1/FAILURE)
Main PID: 3461 (code=exited, status=1/FAILURE)
nov 15 09:38:26 PROJECT systemd[1]: backend.project.service: Unit entered failed state.
nov 15 09:38:26 PROJECT systemd[1]: backend.project.service: Failed with result 'exit-code'.
nov 15 09:38:26 PROJECT systemd[1]: backend.project.service: Service hold-off time over, scheduling restart.
nov 15 09:38:26 PROJECT systemd[1]: Stopped My Server container.
nov 15 09:38:26 PROJECT systemd[1]: backend.project.service: Start request repeated too quickly.
nov 15 09:38:26 PROJECT systemd[1]: Failed to start My Server container.
nov 15 09:38:26 PROJECT systemd[1]: backend.project.service: Unit entered failed state.
nov 15 09:38:26 PROJECT systemd[1]: backend.project.service: Failed with result 'start-limit-hit'.
我尝试了很多解决方案,例如:
- 将我的用户 adminuser 添加到 docker 组
- 将 chmood 777 添加到服务文件
- 在init.d目录下添加
但没有什么能帮助我解决我的问题
我希望有人能帮助我解决我的问题。