1、本地笔记本测试docker同时启动500个容器
首先测试docker daemon支持的最大docker容器数量,查询文档发现,最大容器数量大概是1023个左右,在自己笔记本测试,启动500个容器,需要四分钟,i7、8G,说明docker启动250个容器应该没有任务问题。具体过程在:
https://blog.csdn.net/warrior_0319/article/details/79730191
2、docker系统资源限制
docker创建和使用了很多的系统资源去启动容器,许多系统限制,存在灰色地带取决于你的docker容器配置、你容器中运行的程序、你的硬件设备、docker版本等,下面是总结的一些系统限制:
- 链接到虚拟网络适配器docker0网桥的设备限制:(最多1023/网桥)
- 挂载联合文件系统(AUFS)和shm文件系统:(最大挂载数量1048576)
- 在镜像image上创建的层数layer数量:(最多127layer每个镜像)
- fork出来一个docker-containerd-shim的管理进程:(每个容器平均3M左右,系统最大进程数sysctl kernel.pid_max)
- docker daemon守候进程管理容器的内部数据:(~400k 每个容器)
- 创建内核的cgroup和namespace
- 打开文件描述符:(启动中的容器16个左右) ulimit -n and sysctl fs.file-max
- 端口映射,-p将会在宿主机上为每一个映射的端口启动一个外部进程:(平均每个端口占用~4.5MB每个端口)
- –net=none 和 –net=host将会移除网络消耗。
Container 服务
总的资源消耗取决于你容器内运行的程序,而不是docker本身,如果你在虚拟机中运行应用程序node,ruby,python,java,内存的消耗将是主要问题。
1000个进程会消耗大大量的IO 链接。1000个进程同时运行也会引起大量的上下文交换,
1023 Docker busybox images
nc -l -p 80 -e echo
uses up about 1GB of kernel memory and 3.5GB of system memory.
1023 普通进程
nc -l -p 80 -e echo
host processes running on a host uses about 75MB of kernel memory and 125MB of system memory
Starting 1023 containers serially took ~8 minutes.
Killing 1023 containers serially took ~6 minutes
参考地址:https://stackoverflow.com/questions/21799382/is-there-a-maximum-number-of-containers-running-on-a-docker-host
参考地址:https://groups.google.com/forum/#!topic/docker-user/k5hqpNg8gwQ
参考地址:https://gowalker.org/github.com/portworx/docker_v1.9.0/errors
docker ulimit 设置
–default-ulimit参数可以设置所有容器的 ulimit,他跟docker run命令的–ulimit 参数相同,
// ErrorCodeJoinRunning is generated when we try to network to ourselves.
ErrorCodeJoinRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
Value: “JOINRUNNING”,
Message: “cannot join network of a non running container: %s”,
Description: “An attempt to join the network of a container, but that container isn’t running”,
HTTPStatusCode: http.StatusInternalServerError,
}
OK, after a longer research I’ve got a solution to fix the problem.
The solution is described here: https://coderwall.com/p/myodcq
Finally I just edited the file “/etc/i