英文:
How to get the log of killed containers
问题
我正在Linux中运行Docker来运行某个特定的应用程序。我启动了多个容器并运行一些应用程序,如果应用程序因为xyz原因失败,就会退出容器。现在我想调试容器退出的原因。
许多帖子建议使用 docker logs <容器ID>
,但它只适用于正在运行的容器。
在这个帖子中提供的解决方案 https://stackoverflow.com/questions/43663013/access-logs-of-a-killed-docker-container 不起作用,日志消息显示日期,然后是 -- No entries --
。
那么,如何在退出容器后获取日志文件,而不安装任何外部应用程序来管理日志?
附注:容器被杀死并销毁。
英文:
I'm running docker in linux for some specific application. I start multiple containers and run some application, and exit the container if application fails for xyz reasons. Now I would like to debug the reason for that container to exit.
Many post suggest to use docker logs <container-id>
but it works only with running containers.
Solution given in this post https://stackoverflow.com/questions/43663013/access-logs-of-a-killed-docker-container doesn't work and log message shows date followed by -- No entries --
So how do I get log file even after exiting containers without installing any external application to manage log?
PS: the container is killed and destroyed.
答案1
得分: 1
如果您没有删除那个特定的已停止的容器
(被终止但未销毁),您可以使用docker命令来访问其日志
<br>
docker logs <container_id>
您可以通过以下方式获取已停止容器的Id
<br>
docker ps -f "status=exited"
或者只需使用docker ps -a
(列出所有容器,包括已停止的容器)。
英文:
If you didn't remove that particular stopped container
( killed but not destroyed ) you can access its logs
by using the docker command <br>
docker logs <container_id>
You can get the stopped container Id
by using <br>
docker ps -f "status=exited"
or just by using docker ps -a
(which list all containers including stopped one)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论