【发布时间】:2018-04-12 17:58:37
【问题描述】:
在我的主机中,我有 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 内核?
【问题讨论】:
标签: docker