如何获取已终止容器的日志。

huangapple go评论76阅读模式
英文:

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 &lt;container-id&gt; 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 &lt;container_id&gt;

您可以通过以下方式获取已停止容器的Id<br>

docker ps -f &quot;status=exited&quot;

或者只需使用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 &lt;container_id&gt;

You can get the stopped container Id by using <br>

docker ps -f &quot;status=exited&quot;

or just by using docker ps -a (which list all containers including stopped one)

huangapple
  • 本文由 发表于 2020年1月3日 21:07:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定