タイトルが結論である。
Cloud RunのPHPサンプルを調べているときに、下記のnprocの結果を引数にしているjオプションが気になり、調べた。
RUN docker-php-ext-install -j "$(nproc)" opcache
docker-php-ext-install はPHPのエクステンションをインストールしてくれるシェルスクリプトで、 中身としては make が実行されており、docker-php-ext-install のjオプションも make に渡されている。
while true; do flag="$1" shift case "$flag" in --help|-h|'-?') usage && exit 0 ;; --ini-name) iniName="$1" && shift ;; --jobs|-j) j="$1" && shift ;; --) break ;; *) { echo "error: unknown flag: $flag" usage } >&2 exit 1 ;; esac done
php/docker-php-ext-install at master · docker-library/php · GitHub
makeのjオプションは同時に実行するジョブ数を指定する。
-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.
そのため、
RUN docker-php-ext-install -j "$(nproc)" opcache
上記の記述は、nprocでプロセッサの数を取得し、適した並列実行数で処理することで、効率よくエクステンションをインストールするという1行である。