简体   繁体   English

Docker限制内存使用率不起作用

[英]Docker limit memory usage is not working

When running PHP docker using this command: 使用以下命令运行PHP docker时:

docker run -m 50M -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.0-cli php your-script.php

Where your-script.php has the following content: 其中your-script.php具有以下内容:

<?php
    for ($i = 0; $i > -1; $i++)
        echo $i;
?>

The container keeps running even though memory usage has reached the limit 50M. 即使内存使用量达到了50M的限制,该容器仍将继续运行。

Before running docker run command, executing the following command on host machine: 在运行docker run命令之前,请在主机上执行以下命令:

$ watch "free -m"

Returned: 回来:

             total   used       free     shared    buffers     cached
Mem:           995        634        360          0        116        191

During the docker run command is running I can see the value in free column down to below 200M but the script still keeps running. 在docker run命令运行期间,我可以在free列中看到低至200M以下的值,但脚本仍保持运行。

Your code is only counting, I won't never reach the limit. 您的代码仅在计算,我永远都不会达到极限。 Try creating objects or something like that. 尝试创建对象或类似的东西。

Another thing, measuring the consumed memory with free is very inexact. 另一件事,免费测量消耗的内存非常不准确。 Due to the OS uses memory for cache. 由于操作系统使用内存进行缓存。 Try top and hit E and e to see the values in MB. 尝试顶部,然后按E和e,以MB为单位查看值。

Regards 问候

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

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