首先测试docker daemon支持的最大docker容器数量,查询文档发现,最大容器数量大概是1023个左右,在自己笔记本测试,启动500个容器,需要四分钟,i7、8G,说明docker启动250个容器应该没有任务问题。具体过程在:
https://blog.csdn.net/warrior_0319/article/details/79730191
docker创建和使用了很多的系统资源去启动容器,许多系统限制,存在灰色地带取决于你的docker容器配置、你容器中运行的程序、你的硬件设备、docker版本等,下面是总结的一些系统限制:
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
–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/init/docker.conf” on my Ubuntu 12.04 Docker Host:
Only add “limit nofile 65536 65536”, and the problem is fixed!
Here is the complete file:
description “Docker daemon”
start on filesystem and started lxc-net
stop on runlevel [!2345]
limit nofile 65536 65536
respawn
script
DOCKER=/usr/bin/ UPSTARTJOBDOCKEROPTS=if[−f/etc/default/ U P S T A R T J O B D O C K E R O P T S = i f [ − f / e t c / d e f a u l t / UPSTART_JOB ]; then
. /etc/default/ UPSTARTJOBfi“ U P S T A R T J O B f i “ DOCKER" -d $DOCKER_OPTS
end script
Right now, I’m running a ramp up on a VirtualBox machine (2 vCPUs, 4GByte memory) on my MBP, more than 500 containers already started so far.