sandbox - 如何使用Docker来构建一个沙盒?
PHP中文网
PHP中文网 2017-04-21 10:55:52
0
1
764

最近需要一个sandbox,里面会运行用户的命令、程序。最近初学Docker,所以想利用Docker来实现。

但是看了一些资料,还是没搞明白怎么样才能对Docker容器的内存、CPU、磁盘等进行限制。

昨天试了一下docker run-m参数来限制内存,算是有点用吧。使用-c来限制CPU,貌似不太可行。运行一个无限fork程序就把整个系统给拖死了。

所以想问一下究竟应该是怎么用的?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
刘奇

-c does not mean limiting the CPU usage, but the relative CPU usage of a group of processes. It is a share ratio. Your docker process on the host just acts as an ordinary process with all other processes in units defined by cgroups. CPU scheduling is performed, but the CPU limit unit of the same cgroups will share the CPU usage. Therefore, if you have multiple docker processes in the same cgroups limit unit, they will share the usage, but they cannot be prevented from causing CPU100 together. %.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template