What is the difference between the cpus and cpu_count settings in Docker Compose v2.2?

What is the difference between the cpus and cpu_count settings in Docker Compose v2.2 and which should I use to allocate a number of cores to my container?

I have gathered that cpu_count is analogous to the docker run flag --cpu-count which is for Windows use only, but I can’t find a description of the difference, and the --cpu_count flag is not consistently present in documentation. It is mentioned here:


but not here:

and it is not mentioned in this guide:

I have reviewed this PR:


but it made me more confused because the unit test for cpu_count isn’t skipped like the cpu_percent test when the platform is Windows, even though both options are documented as being “Windows only” in the commandline reference.

Which is supported on which platform(s)? Are they mutually exclusive? Is the documentation inconsistent or am I just reading it incorrectly?

Good Question did you ever work it out?

Any news about this topic?

Can someone from Docker please provide this explanation please?

1 Like

bump? bumpity bump? budabump!

--cpu-count and --cpu-percent is for the HyperV isolation on Windows. When you run a Windows container you have two options.

  1. Using process isolation: You must have the same Windows version in the container than on the host
  2. Using HyperV isolation: You will have a virtualized environment, so the container is actually a VM which requires some CPUs. I don’t remember the default number of CPUs, but if it is 1 or 2, but you have 12 cores, you may want to use more, so you can set --cpu-count.

I haven’t tried it (I don’t use Windows containers) so I am not sure, but I you could probably use --cpu-count=4 and still limit your container to use only one and a half by setting --cpus=2.5

--cpus is for telling Docker if it can use 1 full CPU core or 1 and a half and so on… It actually means that Docker will use the power of maximum 1 and a half CPU cores and tries to use as many cores as it can evenly. In case of 15 cores (if the application supports it), in theory it could use 10 percent of the 15 cores. --cpu-percent is probably does the same on windows with the HyperV layer.

If you want to tell Docker which core the container can use, then you have --cpuset-cpus=1,3. so it would use the first and a third core.

I have a project on GitHub: https://github.com/itsziget/learn-docker

where I tried to demonstrate how --cpus and --cpuset-cpus work.
The Dockerfle: https://github.com/itsziget/learn-docker/blob/master/projects/p09/Dockerfile
and the short tutorial: CPU limit test — Learn Docker documentation

This tutorial is for Linux so I didn’t mention --cpu-count or --cpu-percent.

So as I see:

  • --cpu-count is for the HyperV layer on Windows and there is no alternative to it for containers. Maybe some runtimes have their own configurations to do that.
  • --cpu-percent is for the HyperV layer on Windows to do the same as --cpus for the containers
  • --cpuset-cpus is to tell Docker which available CPU cores can be used by the processes inside the container, but there is no alternative to select CPU cores on Windows for the HyperV layer.

I hope it was clear enough :slight_smile:

1 Like

thank you very much, I will check out your project and see if I can pick up more knowledge on this subject.