出于某种原因,当使用systemd单元文件时,我的docker容器会启动,但会立即关闭.我试过找到日志,但看不出有关为什么会发生这种情况的任何迹象.是否有人知道如何解决这个/找到显示正在发生的事情的日志?
注意:在使用docker start containername启动后手动启动它们然后它可以工作(当使用systemctl start Nginx时)
经过一些挖掘后我发现了这个错误:找不到udev设备:没有这样的设备它可能与此有关吗?
单位服务档案:
[Unit]
Description=Nginx-container
Requires=docker.service
After=docker.service
[Service]
Restart=always
RestartSec=2
StartLimitInterval=3600
StartLimitBurst=5
TimeoutStartSec=5
ExecStartPre=-/usr/bin/docker kill Nginx
ExecStartPre=-/usr/bin/docker rm Nginx
ExecStart=/usr/bin/docker run -i -d -t --restart=no --name Nginx -p 80:80 -v /projects/frontend/data/Nginx/:/var/www -v /projects/frontend: Nginx
ExecStop=/usr/bin/docker stop -t 2 Nginx
[Install]
WantedBy=multi-user.target
Journalctl输出:
May 28 11:18:15 frontend dockerd[462]: time="2015-05-28T11:18:15Z" level=info msg="-job start(d757f83d4a13f876140ae008da943e8c5c3a0765c1fe5bc4a4e2599b70c30626) = OK (0)"
May 28 11:18:15 frontend dockerd[462]: time="2015-05-28T11:18:15Z" level=info msg="POST /v1.18/containers/Nginx/stop?t=2"
May 28 11:18:15 frontend dockerd[462]: time="2015-05-28T11:18:15Z" level=info msg="+job stop(Nginx)"
Docker日志:空(docker logs Nginx)
Systemctl输出:(systemctl status Nginx,Nginx.service)
● Nginx.service - Nginx-container
Loaded: loaded (/etc/systemd/system/multi-user.target.wants/Nginx.service)
Active: Failed (Result: start-limit) since Thu 2015-05-28 11:18:20 UTC; 12min ago
Process: 3378 ExecStop=/usr/bin/docker stop -t 2 Nginx (code=exited,status=0/SUCCESS)
Process: 3281 ExecStart=/usr/bin/docker run -i -d -t --restart=no --name Nginx -p 80:80 -v /projects/frontend/data/Nginx/:/var/www -v /projects/frontend:/Nginx (code=exited,status=0/SUCCESS)
Process: 3258 ExecStartPre=/usr/bin/docker rm Nginx (code=exited,status=0/SUCCESS)
Process: 3246 ExecStartPre=/usr/bin/docker kill Nginx (code=exited,status=0/SUCCESS)
Main PID: 3281 (code=exited,status=0/SUCCESS)
May 28 11:18:20,frontend systemd[1]: Nginx.service holdoff time over,scheduling restart.
May 28 11:18:20 frontend systemd[1]: start request repeated too quickly for Nginx.service
May 28 11:18:20 frontend systemd[1]: Failed to start Nginx-container.
May 28 11:18:20 frontend systemd[1]: Unit Nginx.service entered Failed state.
May 28 11:18:20 frontend systemd[1]: Nginx.service Failed.
If set to simple (the default if neither Type= nor BusName=,but
ExecStart= are specified),it is expected that the process
configured with ExecStart= is the main process of the service.
这意味着如果ExecStart启动的进程退出,则为systemd
将假设您的服务已退出并将清理所有内容.
因为您使用-d运行docker客户端,所以它会退出
立即…因此,systemd清理服务.
通常,在使用systemd启动容器时,您不会使用
-d标志.这意味着客户端将继续运行,并且
将允许systemd收集应用程序生成的任何输出.
也就是说,使用systemd启动Docker容器存在根本问题.由于Docker的运行方式,systemd无法监控容器的状态.所有它真正能做的就是跟踪docker客户端的状态,这不是一回事(客户端可以在不影响容器的情况下退出/崩溃等).这不仅与systemd有关;任何类型的流程主管(upstart,runit,supervisor等)都会遇到同样的问题.