Configure the number of CPUs and memory used by Docker Desktop on Windows

Moderator note by rimelek: Original discussion Upload files to docker Volume


Thanks for your help, I figured it out and everything works, but I can’t solve one more question - the docker uses only 10 processors and I have 24 processors, I tried many ways but I couldn’t allocate 20 processors to the docker, it still uses 10.
I created a .wslconfig file and the assigned RAM is changed in the docker, but the processors do not respond.
I also tried
docker run --cpuset-cpus=“20” myapp:latest
docker run --cpus 20 myapp:latest

I tried to write the name of my container instead of myapp:latest
but all the time I get one error

Unable to find image ‘myapp:latest’ locally
docker: Error response from daemon: pull access denied for myapp, repository does not exist or may require ‘docker login’: denied: requested access to the resource is denied.
See ‘docker run --help’.

my docker container has 10 images of which 5 are in use, I don’t understand, maybe instead of the name of the container I need to enter the names of the images, but when I entered one, some process began that lasted a long time and did not end, just hung, I do this through windows powershell with administrator rights

I tried it on a working container and on a stopped one, but I couldn’t get the result

my .wslconfig file lookls like

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=250GB 

# Sets the VM to use two virtual processors
processors=20

Pleasw, don’t ask unrelated questions in existing topics. I moved the CPU related comments to this new topic.

How is this related to the CPU? You are using an image name that doesn’t exists locally so Docker tries to downlaod it from Docker Hub which it obviously can’t.

What does that mean? What do you expect? How do you know that the container doesn’t use the CPUs?

I guess you mean “processors” here, not “images”.

I’m sorry, but I can’t follow what you are trying. Let’s focus on one thing and make sure you share the context and the details. Also, please format your post according to the following guide: How to format your forum posts

The most important question for me is again: How did you check how many processors Docker used?

1 Like

i see in docker in Containers tab , Container CPU usage - 10 cores allocated and in addition, I see that my processor does not load more than 50 percent during the operation of the container and should be loaded to the maximum

In my docker there is a tab called “images” right after the containers and there is a list of images that belong to the container,
I just follow this instruction to add in docker more processors

but I can’t get the desired result, I don’t know why myapp:latest not work for me and container name not work too

The main thing I want to achieve is to use almost all the power of my processors to run the container

I want to see 20 cores allocated and a processor utilization of 90-100 percent in the windows task manager

This my container on the docker can load the processor to 100%, but it has only 10 cores available and loads them up, so the task manager shows only 40-50% load

When I write less than 10 cores in .wslconfig , it works, 8 and in the docker becomes 8, but when I write more than 10, the value in the docker is still 10 and does not increase, respectively, the processor is loaded by less than half.
Something does not allow the docker to use more than 10 cores, can it be the settings in the container that limit it? maybe you have ideas where else this limitation can be

I see the same number and I have only 12 CPUs (cpu threads). When I get the number of CPU threads in the container, It shows 12.

cat /proc/cpuinfo

Look for “siblings”

Containers by default can use all the CPUs the host have, since a container is not a virtual machine. In case of Docker Desktop, the Desktop has a virtual machine. Or in case of Windows, a WSL2 distribution which is also a container in WSL2 which is itself a virtual machine. I don’t know what Docker Desktop shows it looks like I can use more CPUs then 10 and the container CPU usage shows about 1192% meaning that it is more then the maximum 1000% (10x100%).

Only one image could “belong” to a container. When you write “docker” you actually mean Docker Desktop’s GUI. Docker is running in the virtual machine. The image list is the list of all images you have. There is no container there. The container tab could show containers and compose projects. One compose project can contain multiple images. So I still don’t understand what exactly you mean.

If you really want to test CPU usage, follow my tutorial:

It actually shows how you can build the test image.

Never run commands blindly. You could easily harm your system or lose data. Reading your messages it’s clear to me that you are not familiar with the basics so make sure you learn about it before you continue.

https://container.training/intro-selfpaced.yml.html#1

I copy the relevant part of the cpu test tutorial here too and modify the cpu test command so you can run it more easily:

Dockerfile

# Based on "Petar Maric outdated image"
# https://github.com/petarmaric/docker.cpu_stress_test

FROM ubuntu:20.04

# Update the Ubuntu package index and install the required Ubuntu packages
RUN apt-get update \
 && apt-get install -y --no-install-recommends stress

# Parameterize this Dockerfile, by storing the app configuration within environment variables 
ENV STRESS_TIMEOUT 120
ENV STRESS_MAX_CPU_CORES 1

CMD stress --cpu $STRESS_MAX_CPU_CORES --timeout $STRESS_TIMEOUT

Build the image

docker build -t localhost/stress .

Test 15 CPUs (or any number of cpus you choose)

CPUS=15
docker run -it --rm \
  -e STRESS_MAX_CPU_CORES=$CPUS \
  -e STRESS_TIMEOUT=30 \
  --cpus=$CPUS \
  localhost/stress

Then you have 30 seconds to see the result in Docker Desktop’s containers tab, but it won’t show you more then 10 cores allocated. Only the cpu usage will show about 1500%.

2 Likes

thank you very much
you are a genius
thank you for your help and your time
You’ve been a great help.
you are a great man
all the best
I’ll do my best