1

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?

Serhii C.
  • 31
  • 1
  • 1
  • 4
  • 2
    If I understand this document correctly https://docs.docker.com/engine/admin/resource_constraints/#configure-the-default-cfs-scheduler You use those commands to select which cpu cores it should use. If you want to run multiple docker containers, you use the run command multiple times, or use a docker-compose. Hope this helps – H. Hakvoort Oct 18 '17 at 14:34
  • @H.Hakvoort can I use Docker Swarm for one machine to make as many workers, as I want? – Serhii C. Oct 18 '17 at 14:47
  • I suppose you could. – H. Hakvoort Oct 18 '17 at 14:53

2 Answers2

3

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.

James Moser
  • 396
  • 1
  • 6
0

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/

Stanislav Mekhonoshin
  • 3,641
  • 2
  • 18
  • 25
  • Thanks for the answer. How can I implement multi-containers with wercker? Because I don't use a docker-compose. – Serhii C. Oct 19 '17 at 07:19
  • Update: 'docker-compose scale' is now obsolete. suggestion is to use 'docker-compose up': https://docs.docker.com/compose/reference/up/ – Brett Rigby May 14 '18 at 09:43