kurtgn
kurtgn

Reputation: 8732

docker container - difference between host and guest cpu cores

In my host machine, I have 4 cpu cores (as per Python multiprocessing library):

python

Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> multiprocessing.cpu_count()
4

However when I run Python in a Docker container it says something different:

docker run -it python

Python 3.6.5 (default, Mar 31 2018, 01:15:58)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> multiprocessing.cpu_count()
2

Also, when I try to add more CPUs to the container I get an even stranger response:

docker run -it --cpuset-cpus "4" python
docker: Error response from daemon: Requested CPUs are not available - requested 4, available: 0-1.

why is that? And how do I make my container see all my CPU cores?

Upvotes: 1

Views: 307

Answers (1)

vcsjones
vcsjones

Reputation: 141703

Judging from the presence of "Darwin" in your initial output, your host is macOS.

Docker containers on a Mac actually run in a Linux virtual machine. The VM has its own configuration for memory and CPU.

enter image description here

Upvotes: 1

Related Questions