如何让Docker使用所有CPU核心?

And*_*owe 7 docker

我试图让 Docker 使用我的硬件上所有可用的 CPU 内核 (4)。Docker只能看到一个CPU核心:

$ docker run --cpuset-cpus="0-3" -ti ubuntu bash
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Requested CPUs are not available - requested 0-3, available: 0.
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.
Run Code Online (Sandbox Code Playgroud)

如何让 Docker 使用所有可用的内核?

Docker 文档声称将 cpus 标志设置为 0.000 会强制 Docker 使用所有可用的内核,但这对我不起作用:

$ docker run --cpus=0.000  -ti ubuntu bash
root@36855ab28928:/# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 58
model name      : Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
stepping        : 9
microcode       : 0x19
cpu MHz         : 2890.620
cache size      : 4096 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 popcnt aes xsave avx rdrand hypervisor lahf_lm pti fsgsbase
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips        : 5781.24
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:
Run Code Online (Sandbox Code Playgroud)
$ docker run --cpus=0.000 -ti ubuntu bash
root@6c1d6934a0fe:/# lscpu | head -n 10
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              1
On-line CPU(s) list: 0
Thread(s) per core:  1
Core(s) per socket:  1
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
root@6c1d6934a0fe:/#
Run Code Online (Sandbox Code Playgroud)

我正在使用 Docker 快速启动终端来获取您在上面看到的命令提示符。

我的物理硬件是 Windows 10 笔记本电脑。在 Windows 上的 Ubuntu 上使用 Bash:

$ lscpu | head -n 10
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  2
Core(s) per socket:  2
Socket(s):           1
Vendor ID:           GenuineIntel
CPU family:          6
Run Code Online (Sandbox Code Playgroud)

我安装了 Oracle VM Virtualbox,但我不知道这是否与此有关。我是一个 Docker 新手。Stack Overflow( 1 )上的其他答案声称默认情况下所有CPU都是可用的,并且在网上没有找到相反的信息。我浏览了 Docker 文档,没有发现任何内容表明我需要做一些特殊的事情来解锁其他 CPU 核心。

小智 3

这很可能是由于您安装了 Docker 造成的。Docker 默认情况下可以使用所有系统资源。Toolbox 安装使用 Virtualbox 中的 VM。您应该增加 Virtualbox 上虚拟机的资源。

如果您使用的是 Windows 10,则不应使用 Docker Toolbox,因为它仅适用于旧版操作系统 (Win 7)。您应该使用 Docker CE。