Reputation: 845
I have been working with Docker for a while now, I have installed docker and launched a container using
docker run -it --cpuset-cpus=0 ubuntu
When I log into the docker console and run
grep processor /proc/cpuinfo | wc -l
It shows 3 which are the number of cores I have on my host machine.
Any idea on how to restrict the resources to the container and how to verify the restrictions??
Upvotes: 9
Views: 42622
Reputation: 74740
Containers aren't complete virtual machines. Some kernel resources will still appear as they do on the host.
In this case, --cpuset-cpus=0
modifies the resources the container cgroup has access to which is available in /sys/fs/cgroup/cpuset/cpuset.cpus
. Not what the VM and container have in /proc/cpuinfo
.
One way to verify is to run the stress-ng
tool in a container:
Using 1 cpu will be pinned at 1 core (1 / 3 cores in use, 100% or 33% depending on what tool you use):
docker run --cpuset-cpus=0 deployable/stress -c 3
This will use 2 cores (2 / 3 cores, 200%/66%):
docker run --cpuset-cpus=0,2 deployable/stress -c 3
This will use 3 ( 3 / 3 cores, 300%/100%):
docker run deployable/stress -c 3
Memory limits are another area that don't appear in kernel stats
$ docker run -m 64M busybox free -m
total used free shared buffers cached
Mem: 3443 2500 943 173 261 1858
-/+ buffers/cache: 379 3063
Swap: 1023 0 1023
yamaneks answer includes the github issue.
Upvotes: 7
Reputation: 845
docker inspect <container_name>
will give the details of the container launched u have to check for "CpusetCpus" in there and then u will find the details.
Upvotes: 9
Reputation: 51778
The issue has been already raised in #20770. The file /sys/fs/cgroup/cpuset/cpuset.cpus
reflects the correct output.
The cpuset-cpus
is taking effect however is not being reflected in /proc/cpuinfo
Upvotes: 14
Reputation: 6537
it should be in double quotes --cpuset-cpus="", --cpuset-cpus="0" means it make use of cpu0.
Upvotes: -3