docker: Error response from daemon: range of CPUs is from 0.01 to 24.00, as there are
only 24 CPUs available means --cpus asked for more CPUs than the Docker
engine can see. Give a value at or below the number in the message; read it with
docker info --format "{{.NCPU}}".
On this machine the message and docker info both read 24. A value of 24
started, 25 did not.
The error
docker run --name fix12-dkrun-cpu --cpus 999 alpine true
docker: Error response from daemon: range of CPUs is from 0.01 to 24.00, as there are only 24 CPUs available
Run 'docker run --help' for more information
The exit code was 125 and no container was created; the listing of the test's containers
that started the next script showed no fix12-dkrun-cpu.
Why it happens
--cpus is a share of CPU time, written as a number of CPUs, and the message
prints both ends of the range this engine accepts. 999 is far outside it, and
so was 25, one more than the count.
The lower end gave a different message. --cpus 0.001 did not print the range;
it failed with a longer line that ends in cpu.max: invalid argument:
docker run --rm --cpus 0.001 alpine true
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error setting cgroup config for procHooks process: failed to write "100 100000": write /sys/fs/cgroup/docker/651d6f6687b185ea20e83f9d8d2bfdd4d0caf51fdeb6b88d8292bc7953c937e7/cpu.max: invalid argument
...
The ... stands for the blank line and the "Run 'docker run --help'" line that
follow it, as under the main error.
The fix
docker info --format "{{.NCPU}}"
24
docker run --rm --cpus 2 alpine sh -c "cat /sys/fs/cgroup/cpu.max"
200000 100000
The first line reads the count the engine reports. The second starts a container with
--cpus 2 and prints its cgroup file cpu.max, which read
200000 100000. --cpus 24 also started. To give a Desktop engine
more CPUs you would change the VM's resources in Docker Desktop's settings (not done here);
a value that fits the engine you have is the simpler fix.
How it was reproduced
Docker Desktop 4.99.0 on Windows 11, client and engine 29.9.3, runc 1.5.2, the cached
alpine:latest image (Alpine 3.24.2). A PowerShell script ran each command
through cmd /c with stderr merged into stdout, so the commands are shown
without a prompt. Runs: --cpus 999 and 25 gave the range
message, 0.001 the cgroup message, 2 and 24 started.
The container name fix12-dkrun-cpu is the test's own.
Frequently asked
- How many CPUs can a Docker container use?
- Up to the number in the message. On the test PC both the message and docker info --format "{{.NCPU}}" read 24, and --cpus 24 started while --cpus 25 was refused.
- What does docker run --cpus 2 set inside the container?
- In the test the container's /sys/fs/cgroup/cpu.max read 200000 100000 with --cpus 2.
- What is the smallest value for docker run --cpus?
- The message says 0.01. A smaller value, 0.001, did not print the range in the test; it failed with a cgroup error ending in cpu.max: invalid argument.
More decoded errors in the Fixes category. For the memory flag of the same command, see Minimum memory limit allowed is 6MB.