如何将 docker 镜像作为 systemctl 服务运行?

如何将 docker 镜像作为 systemctl 服务运行?

我正在遵循说明这里,使用‘docker run’。

我想到了以下情况。容器启动,然后停止。我遗漏了什么?事实上,systemctl status 向我显示了日志的尾部;日志的其余部分在哪里?

[Unit]
Description=Jenkins
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker run -d -p 49001:8080 -v /var/jenkins_home:/var/jenkins_home -t jenkins
ExecStop=/usr/bin/docker stop -t 2 jenkins
#ExecStopPost=/usr/bin/docker rm -rf jenkins

[Install]
WantedBy=default.target

我设法从状态中获取了更多有用的数据。但我很困惑:我可以复制并粘贴 ExecStart 命令行并且它可以工作,但 systemctl 会报告退出状态。

docker-jenkins.service - Jenkins
   Loaded: loaded (/etc/systemd/system/docker-jenkins.service; disabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Wed 2016-10-26 08:45:58 EDT; 4s ago
  Process: 23529 ExecStopPost=/usr/bin/docker rm -f jenkins_server (code=exited, status=1/FAILURE)
  Process: 23521 ExecStop=/usr/bin/docker stop -t 2 jenkins_server (code=exited, status=1/FAILURE)
  Process: 23516 ExecStart=/usr/bin/docker run -d -p 49001:8080 -v /var/jenkins_home:/var/jenkins_home --env JAVA_OPTS="-Djavax.net.ssl.trustStore=/var/jenkins_home/.keystore/cacerts -Djavax.net.ssl.trustStorePassword=changeit" --name jenkins_server jenkins (code=exited, status=125)
 Main PID: 23516 (code=exited, status=125)

Oct 26 08:45:58 cnode10.basistech.net systemd[1]: Unit docker-jenkins.service entered failed state.
Oct 26 08:45:58 cnode10.basistech.net systemd[1]: docker-jenkins.service failed.
Oct 26 08:45:58 cnode10.basistech.net systemd[1]: docker-jenkins.service holdoff time over, scheduling restart.
Oct 26 08:45:58 cnode10.basistech.net systemd[1]: start request repeated too quickly for docker-jenkins.service
Oct 26 08:45:58 cnode10.basistech.net systemd[1]: Failed to start Jenkins.
Oct 26 08:45:58 cnode10.basistech.net systemd[1]: Unit docker-jenkins.service entered failed state.
Oct 26 08:45:58 cnode10.basistech.net systemd[1]: docker-jenkins.service failed.

相关内容