在我的主机中,我有4个cpu核心(根据Python multiprocessing
库):
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
然而,当我在Docker容器中运行Python时,它会说不同的东西:
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
此外,当我尝试向容器添加更多CPU时,我得到一个更奇怪的回应:
docker run -it --cpuset-cpus "4" python
docker: Error response from daemon: Requested CPUs are not available - requested 4, available: 0-1.
为什么?如何让我的容器看到我所有的CPU内核?