LoginSignup
0
0

Laravel - Dockerfileでnode.jsを導入時setup_.xxが使用できない時

Posted at

DockerでPHP(Laravel)の環境構築をしていた際、node.jsの導入において
以前記述していたスクリプトが使用できずエラーになりました。

結論、Dockerfileの内容を以下のサイトに記載されている内容に変更することで解決しました。
https://github.com/nodesource/distributions/blob/master/README.md

以前のDockerfile内容(node.jsの部分だけ抜粋)

FROM php:8.2.0-apache
<・・・中略・・・>
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs

エラー内容

 => ERROR [<アプリ名> stage-0 9/9] RUN apt-get install -y nodejs                                                                                                                              1.1s
------
 > [<アプリ名> stage-0 9/9] RUN apt-get install -y nodejs:
#0 0.177 Reading package lists...
#0 0.450 Building dependency tree...
#0 0.532 Reading state information...
#0 0.618 The following NEW packages will be installed:
#0 0.618   nodejs
#0 1.017 0 upgraded, 1 newly installed, 0 to remove and 42 not upgraded.
#0 1.017 Need to get 28.1 MB of archives.
#0 1.017 After this operation, 188 MB of additional disk space will be used.
#0 1.017 Err:1 https://deb.nodesource.com/node_18.x bullseye/main arm64 nodejs arm64 18.17.1-deb-1nodesource1
#0 1.017   404  Not Found [IP: 172.67.10.205 443]
#0 1.033 E: Failed to fetch https://deb.nodesource.com/node_18.x/pool/main/n/nodejs/nodejs_18.17.1-deb-1nodesource1_arm64.deb  404  Not Found [IP: 172.67.10.205 443]
#0 1.033 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

原因

GitHub上の「nodesource README.md」を確認したところ、New Updateということでインストール方法の変更がありました。
その中でインストールスクリプトとして存在した「setup_XX.x」はもうサポートがされないと記載があり、そのため以前使用していたスクリプトは使用不可、404(ページがなかった)となっていたようです。

今回実施した解決策

そのため、以下のサイトを参考にDockerfileを修正しました(node.jsの部分だけ抜粋)
https://github.com/nodesource/distributions/blob/master/README.md

FROM php:8.2.0-apache
<・・・中略・・・>
RUN apt-get update \
  && apt-get install -y ca-certificates curl gnupg \
  && mkdir -p /etc/apt/keyrings \
  && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
  && NODE_MAJOR=18 \
  && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
  && apt-get update && apt-get install nodejs -y

この記述に変更したところ、きちんとnode.jsが導入されました。

後日もう一度「setup_xx」を試した結果→なぜか上手く導入された

今回エラーが発生した際に上記の方法で対応したのですが、後日念のため以前のDockerfileで導入したところ、エラーが発生しませんでした。
まだ理由は分かっていないのですが、もし同様のエラーが出た際、この内容を参考に修正をしてみてください。

構築時にエラーが出ると困るので、今後は修正後の内容で構築しようと考えています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0