現象
希望針對已啟動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