How many containers should I run in one DO droplet?

Posted March 20, 2015 6.6k views

Currently, I’m running 5 applications in Docker containers in one 10GB droplet. These usually run fine when they’ve all been deployed. There apps get very little traffic, so it doesn’t make sense to give them that much space when only a couple of people a day visit them.

The problem is that, sometimes, when I deploy one of my applications my droplet goes to 100% CPU usages or I get a ‘Cannot allocate memory’ error. Every time I deploy an app I’m basically building the image and the running the container (fig build and fig up).

Am I doing something wrong? I do I just actually need a new droplet?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

There isn’t really an upper limit on the number of Docker containers that can be run on a single host beyond whatever resources the processes need. In some larger deployments, people will run hundreds of containers on the same host. If you haven’t yet done so, the first thing I’d recommend is adding a SWAP file to the server. It will give you a little more leeway regarding memory usage. Check out this tutorial for all the details:

If it’s just the building of the image that’s leading to the memory errors, then that might do it.

If the applications in the containers are what’s using up the resources, then you might want to constrain them. Docker allows you to restrict the amount of memory and cpu that is available for each container. This great blog post gets into the specifics. The fig documentation notes that you can specify a mem_limit in your fig.yml file.

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.

Awesome response! Thanks Andrew. I’ll take a look at these.