pythondockerubuntucontainersvirtualization

Python docker sdk how to set cpu count in containers.run


I am using docker SDK for python 3 and running a container using

containers.run

We would like to set the number of CPU cores the container is getting and looked here

There we saw there is a way to set the number of cores only under windows

How can you do it in Ubuntu via that sdk in Python?

If not at all, How can i control the container getting 1 core, 2 cores etc.?


Solution

  • you may use cpuset_cpus

    cpuset_cpus (str) – CPUs in which to allow execution (0-3, 0,1).

    so it looks like:

    client.containers.run('alpine', cpuset_cpus="1")