gpt4 book ai didi

dockerfile - -j 选项对 docker-php-ext-install 有什么作用?

转载 作者:行者123 更新时间:2023-12-04 14:54:54 24 4
gpt4 key购买 nike

我已经阅读了很多为您的特定 PHP 设置创建 dockerfile 的示例,包括安装扩展。 docker-php-ext-install命令有时包括 -j$(nproc)作为一种选择。那里到底发生了什么?我怀疑 nproc和进程数有关系吗?

这是来自 https://github.com/docker-library/docs/tree/master/php#php-core-extensions 的示例

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd

我是 docker 新手,想准确了解每个步骤中发生的事情,而不是盲目地从各种示例和教程中复制和粘贴内容。

最佳答案

它是 make 的作业数脚本中包含的调用 docker-php-ext-install (行 53 将选项存储在变量 $j105-106 调用 make -j$j 中)。
命令 nproc直接向脚本提供可用于您的系统的物理线程数。例如,在我的系统上,它将减少为:

make -j$(nproc) -> make -j8
因此它使用 8 个并行配方运行 make。
来自 make manual :

-j [jobs], --jobs[=jobs]:Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j option, the last one is effective. If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously.


更多信息在 GNU make关于 parallel jobs 的文档:

GNU make knows how to execute several recipes at once. Normally, make will execute only one recipe at a time, waiting for it to finish before executing the next. However, the -j or --jobs option tells make to execute many recipes simultaneously. [...] On MS-DOS, the -j option has no effect, since that system doesn’t support multi-processing.

If the -j option is followed by an integer, this is the number of recipes to execute at once; this is called the number of job slots. If there is nothing looking like an integer after the -j option, there is no limit on the number of job slots. The default number of job slots is one, which means serial execution (one thing at a time).


理想情况下,如果该数字等于 的数量物理线程可用(大约是处理器的数量,或者在这种情况下是由 nproc 返回的数量),您应该得到 最快的编译速度 .

nproc is a linux command - see man nproc too. It means "number of processing units available" - your CPU Cores. You can imagine it as "Number of processors" [source: @tron5 comment]


您必须 考虑可用内存 尽管。例如,如果您分配 8 个插槽,只有 1GB 的 RAM,并且 3 个同时进行的作业的编译填满了 RAM,那么当第四个作业启动时,它会因内存不足而错误退出,从而阻止整个编译过程。

关于dockerfile - -j 选项对 docker-php-ext-install 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46957429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com