I have a 4-core CPU, I want to allocate 50% CPU resource to a docker container.
After reading the docker-run manual and config.go source code.
I still don\'t know ho
It depends on the environment, so there is no straight answer but keep reading.
From the docker run --help command:
-c, --cpu-shares=0 CPU shares (relative weight)
Since Docker is based on cgroups. The CPU will be distributed among the running containers. By default the value is 1024.
cat /sys/fs/cgroup/cpu/docker/cpu.shares
1024
So, if we have 2 containers, one for the database and one more for the web server
sudo docker run -c 614 -dit --name db postgres /postgres.sh
sudo docker run -c 410 -dit --name web nginx /nginx.sh
Will give 60% to the db container (614 is 60% of 1024) and 40% to the web container.
For further reading see:
cpuset option: --cpuset="" CPUs in which to allow execution (0-3, 0,1)