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

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

问题描述

我有一个在1G RAM主机中运行的Docker容器(也有在同一主机中运行的其他容器).该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终止了您的应用程序,则该行将为true.您可能还需要查找退出代码,以查看它是否确定您的应用退出的原因.

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天全站免登陆