简体   繁体   English

从容器内部检查Docker容器的统计信息

[英]Checking docker container's stats from inside the container

I am writing a healthcheck routine for a docker container. 我正在为Docker容器编写运行状况检查例程。 By design it should check how much CPU and memory it's using and return an "unhealthy" 1 if they exceed limits. 根据设计,它应该检查正在使用的CPU和内存量,如果超出限制,则返回“不正常” 1

Is there a way to check container CPU and memory usage from INSIDE the container by running a .sh script? 有没有一种方法可以通过运行.sh脚本从容器内部检查容器CPU和内存使用情况?

All metrics are available in cgroup filesystem inside container. 所有度量标准都在容器内的cgroup文件系统中可用。 Read more here: https://docs.docker.com/config/containers/runmetrics 在此处阅读更多信息: https : //docs.docker.com/config/containers/runmetrics

The client is connected to the docker socket (/var/run/docker.sock), which is not available inside the container. 客户端连接到Docker套接字(/var/run/docker.sock),该套接字在容器内部不可用。 A workaround would be to mount host's /var/run/docker.sock into the container with the following option when you are starting the container: -v /var/run/docker.sock:/var/run/docker.sock 一种解决方法是在启动容器时使用以下选项主机的/var/run/docker.sock装入容器:-v /var/run/docker.sock:/var/run/docker.sock

For example, docker run -it -v /var/run/docker.sock:/var/run/docker.sock $MY_IMAGE_NAME 例如,docker run -it -v /var/run/docker.sock:/var/run/docker.sock $ MY_IMAGE_NAME

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

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