简体   繁体   English

Docker 容器不断重启

[英]Docker container keeps restarting

I was trying rancher.我正在尝试牧场主。 I used the command: sudo docker run -d --restart=always -p 8080:8080 rancher/server to start run it.我使用命令: sudo docker run -d --restart=always -p 8080:8080 rancher/server 开始运行它。 Then I stopped the container and removed it.然后我停止了容器并将其移除。 But if I stop and restart the docker daemon or reboot my laptop, and lookup running containers using docker ps command, it will have rancher server running again.但是,如果我停止并重新启动 docker 守护程序或重新启动我的笔记本电脑,并使用 docker ps 命令查找正在运行的容器,它将再次运行 Rancher 服务器。 How do I stop/remove it completely and make sure it will not run again.如何完全停止/删除它并确保它不会再次运行。

Note: following issue 11008 and PR 15348 ( commit fd8b25c , docker v1.11.2), you would avoid the issue with:注意:在问题 11008PR 15348提交 fd8b25cdocker v1.11.2)之后,您可以通过以下方式避免该问题:

sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server

In your current situation, thanks to PR 19116 , you can use docker update to update the restart policy.在您目前的情况下,感谢PR 19116 ,您可以使用docker docker update来更新重启策略。

docker update --restart=unless-stopped <yourContainerID_or_Name>

Then stop your container, restart your docker daemon: it won't restart said container.然后停止你的容器,重启你的 docker 守护进程:它不会重启所述容器。


The OP codefire points to another reason in the comments : OP codefire 在评论中指出了另一个原因:

When I first ran the start rancher server command, I didn't notice that it was being downloaded.当我第一次运行 start rancher server 命令时,我没有注意到它正在被下载。 So I may have retried that command a couple times.所以我可能已经重试了几次该命令。

That must be why the job kept on restarting even after stopping and removing containers that was started as rancher server.这一定是为什么即使在停止和删除作为 Rancher 服务器启动的容器后,作业仍会继续重新启动的原因。
After stopping and removing 8+ containers, it finally stopped停止并移除 8+ 个容器后,它终于停止了

That is why I have aliases to quickly remove any stopped containers .这就是为什么我有别名来快速删除任何停止的容器

it keeps restarting because you're using --restart=always flag它不断重新启动,因为您正在使用--restart=always标志

Run运行

docker logs <CONTAINER_ID>

to see if your code is encountering any errors that does not allow the container to run properly查看您的代码是否遇到任何不允许容器正常运行的错误

These solutions are correct.这些解决方案是正确的。 But for me there was a situation when these answers did not work out.但对我来说,有一种情况是这些答案没有奏效。 That's because I was running service in the background I did not remove it so it keeps running even you remove container it will restart it again and so on.. So answer to that specific problem is那是因为我在后台运行服务我没有删除它所以即使你删除容器它也会继续运行它会再次重新启动它等等..所以这个具体问题的答案是

docker service rm service name or id

Docker run in your locahost if you shutdown/kill docker damen then docker stop and inside in docker container delete data if you not save your data in external volume.如果您关闭/杀死 docker damen,则 Docker 在您的 locahost 中运行,然后 docker stop 和 inside 在 docker 容器中删除数据,如果您不将数据保存在外部卷中。

docker run -d nginxlogs:/var/log/nginx -p 5000:80 nginx docker run -d nginxlogs:/var/log/nginx -p 5000:80 nginx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM