【问题标题】:docker container - difference between host and guest cpu coresdocker 容器 - 主机和来宾 cpu 核心之间的区别
【发布时间】: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


    【解决方案1】:

    从您的初始输出中是否存在“Darwin”来看,您的主机是 macOS。

    Mac 上的 Docker 容器实际上在 Linux 虚拟机中运行。 VM 有自己的内存和 CPU 配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-18
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 2017-11-21
      • 2020-01-07
      • 1970-01-01
      相关资源
      最近更新 更多