如何知道 docker 容器退出的原因? [英] How to know the reason why a docker container exits?

查看:115
本文介绍了如何知道 docker 容器退出的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Docker 容器在 1G RAM 的主机上运行(同一主机上还有其他容器运行).这个 Docker 容器中的应用程序会解码一些图像,这可能会消耗大量内存.

I have a Docker container running in a host of 1G RAM (there are also other containers running in the same host). The application in this Docker container will decode some images, which may consume memory a lot.

此容器会不时退出.我怀疑这是由于内存不足,但不是很确定.我需要一种方法来找到根本原因.那么有没有办法知道这个容器的死亡发生了什么?

From time to time, this container will exit. I doubt it is due to out of memory but not very sure. I need a method to find the root cause. So is there any way to know what happened for this container's death?

推荐答案

其他人提到了 docker logs $container_id 来查看应用程序的输出.这始终是我要检查的第一件事.

Others have mentioned docker logs $container_id to view the output of the application. This would always be my first thing to check.

接下来,您可以运行 docker inspect $container_id 来查看状态的详细信息,例如:

Next, you can run a docker inspect $container_id to view details on the state, e.g.:

    "State": {
        "Status": "exited",
        "Running": false,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 0,
        "ExitCode": 2,
        "Error": "",
        "StartedAt": "2016-06-28T21:26:53.477229071Z",
        "FinishedAt": "2016-06-28T21:26:53.478066987Z"
    },

重要的一行是OOMKilled",如果您超过容器内存限制并且 Docker 杀死您的应用程序,这将是正确的.您可能还想查找退出代码,看看它是否确定了您的应用退出的原因.

The important line there is "OOMKilled" which will be true if you exceed the container memory limits and Docker kills your app. You may also want to lookup the exit code to see if it identifies a cause for the exit by your app.

注意,这仅表明 docker 本身是否会终止您的进程,并要求您为容器设置内存限制.在 docker 之外,如果主机本身的内存不足,Linux 内核可以大声笑你的进程.发生这种情况时,Linux 通常会写入/var/log 中的日志.使用 Windows 和 Mac 上的 Docker Desktop,您可以在 docker 设置中调整分配给嵌入式 Linux VM 的内存.

Note, this only indicates if docker itself kills your process, and requires that you have set a memory limit on your container. Outside of docker, the Linux kernel can lol your process if the host itself runs out of memory. Linux often writes to a log in /var/log when this happens. With Docker Desktop on Windows and Mac, you can adjust the memory allocated to the embedded Linux VM in the docker settings.

这篇关于如何知道 docker 容器退出的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆