This post was updated 470 days ago and some of the ideas may be out of date.

使用docker创建容器限制swap交换空间时出现如下警告:

root@localhost:/project# docker run --rm --memory-swap 128m php-swoole-5.0.1
WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.

一番百度后发现是系统未开启swap限制。

解决方案

将/etc/default/grub文件中的GRUB_CMDLINE_LINUX参数,修改为

GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"

然后使用sudo update-grub 更新系统中的grub配置文件后,重启系统即可。