为避免攻击者在容器内使用命令启动fork炸弹,造成拒绝服务,建议用户设置全局默认的ulimit,对创建的文件句柄、进程数进行限制。
在配置文件中找到“/usr/bin/dockerd”所在行,并在该行后面增加nofile(创建的文件句柄)参数和nproc(进程)参数的限制。
修改示例如下,请根据实际情况设置对应的值。
... # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker /usr/bin/dockerd --default-ulimit nofile=20480:40960 --default-ulimit nproc=1024:2048 ...
其中--default-ulimit nproc=1024:2048表示限制进程数量为1024个,可以在进程中修改该值,但是不能超过2048,且第一个值要小于或等于第二个值。nofile配置含义同nproc。