Serhii C.
Serhii C.

Reputation: 61

How can I run multiple Docker containers?

I want to run as many Docker containers, as many I have CPU cores. So, I used command: docker run --cpus="16" --link=mongo_dev:mongodb -d -p 8001:8000 --name app myapp

Also, I tried:

docker run --cpuset-cpus="0-15" --link=mongo_dev:mongodb -d -p 8001:8000 --name app myapp

But it runs only one container. Or did I misunderstand the use of this command? Is it real to run a multiple Docker containers in one machine? As I know, I can't use node.js cluster module to make multiple instances of my app in one Docker container because it runs only in 1 CPU core, does it?

Upvotes: 3

Views: 38704

Answers (2)

James Moser
James Moser

Reputation: 506

Yes. You can run multiple containers on one server, and it is not restricted to the number of CPUs.

Your command creates and starts exactly 1 container that has access to at most 16 CPUs (and in the 2nd example only precisely CPUs 0-15).

What you want to do is execute your command N times for N containers. If you wish to restrict containers to use only one CPU each use --cpus=1. If you further wish to restrict containers to never share a CPU, use --cpuset-cpus=I, where I is an integer 0-15 for each container. But in reality, the kernel is pretty good at scheduling, unless you are doing additional tuning, I would let it do it's job.

Upvotes: 4

Stanislav Mekhonoshin
Stanislav Mekhonoshin

Reputation: 4386

If you use docker-compose, you can use scale parameter to run multiple instances of the same image.

This was already answered here docker-compose creating multiple instances for the same image

And check out the official doc for docker-compose https://docs.docker.com/compose/reference/scale/

Upvotes: 2

Related Questions