现象
希望针对已启动ubuntu16.04容器进行内存限制,运行后报错
$ docker update ubuntu:16.04 --memory-swap -1 -m 512M
ubuntu:16.04
Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.
解决
显然,docker提示系统不支持cgroup内存限制,需要手动开启。
解决方案是在/boot/cmdline.txt
尾部加入 cgroup_enable=memory cgroup_memory=1
后重启
再次运行改动已生效
$ docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9e57861d5ac7 ubuntu 1.12% 5.113MiB / 512MiB 0.73% 0B / 0B 0B / 0B 38