docker run -it --rm -m 100M ubuntu-stress:latest /bin/bash
按照官方文档的理解,如果指定 -m
内存限制时不添加 --memory-swap
选项,则表示容器中程序可以使用 100M 内存和 100M swap 内存。默认情况下,--memory-swap
会被设置成 memory 的 2倍。
We set memory limit(300M) only, this means the processes in the container can use 300M memory and 300M swap memory, by default, the total virtual memory size --memory-swap
will be set as double of memory, in this case, memory + swap would be 2*300M, so processes can use 300M swap memory as well.
如果按照以上方式运行容器提示如下信息:
WARNING: Your kernel does not support swap limit capabilities, memory limited without swap.
当主机没有swap交换分区的时候,无法设置cgroup。
解决办法:
sudo echo 1 > /sys/fs/cgroup/docker/cgroup.clone_children
If it still does not work, run below commands and restart docker service:
sudo echo 0 > /sys/fs/cgroup/docker/cpuset.mems
sudo echo 0 > /sys/fs/cgroup/docker/cpuset.cpus
© 著作权归作者所有