By default, each container’s access to the host machine’s CPUs is unlimited. You can set various constraints to limit a given container’s access to the host machine’s CPUs.
Having completed lab 00 - Setup lab environment
$ cd <GIT_REPO_NAME>/vagrant
$ vagrant up
$ vagrant ssh
vagrant@docker-vm:~$
Get the Docker Host (Ubuntu VM in this case) total CPUs available:
vagrant@docker-vm:~$ cat /proc/cpuinfo | grep processor | wc -l
2
Run a container to test the Max CPUs seen by a Java application
vagrant@docker-vm:~$ docker run \
--rm \
-v $(pwd)/app:/app/ \
openjdk:11.0-jdk \
/usr/local/openjdk-11/bin/java \
/app/MaxProcessors.java
Max Processors: 2
Run a container with `--cpus 1 flag (1/2 of the host's CPUs)
vagrant@docker-vm:~$ docker run \
--rm \
--cpus 1 \
-v $(pwd)/app:/app/ \
openjdk:11.0-jdk \
/usr/local/openjdk-11/bin/java \
/app/MaxProcessors.java
Max Processors: 1