How many containers should I run in one DO droplet?

March 20, 2015 3k views
Docker DigitalOcean Ubuntu

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?

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.

Have another answer? Share your knowledge.