概要
- 他の方が作ってくれたのLaravelアプリケーションローカル開発環境のAmazonLinux2コンテナにNode.jsを入れている部分の処理をまとめてみる
Node.jsの入れている部分Dockerfile
-
下記のような処理をしている。
RUN curl -fsSL https://rpm.nodesource.com/setup_14.x | bash - RUN yum -y install nodejs && \ npm i -g n && \ n 14
-
理解しやすくするため&&と\で一行に記載されている部分を冗長だがRUNになおしてみる。
RUN curl -fsSL https://rpm.nodesource.com/setup_14.x | bash - RUN yum -y install nodejs RUN npm i -g n RUN n 14
-
上記に対して一行づつ見てゆく。
何をしているんだろう
-
下記の処理に一行づつコメントを入れて何をしているか解説してみる。
RUN curl -fsSL https://rpm.nodesource.com/setup_14.x | bash - RUN yum -y install nodejs RUN npm i -g n RUN n 14
-
コメントを追加した
# Node.js14系のyumリポジトリを追加 RUN curl -fsSL https://rpm.nodesource.com/setup_14.x | bash - # Node.jsを一旦インストール(npmコマンドを実行するためだけ) RUN yum -y install nodejs # 「n」というNode.jsのバージョン管理ツールを取得 # npm i は npm installの省略記法 RUN npm i -g n # 「n」を用いてNode.js14系のインストールを実行 RUN n 14
-
RUN curl -fsSL https://rpm.nodesource.com/setup_14.x | bash -
について- Node.jsのリポジトリを追加している。
- こちらにコマンドが記載されているhttps://github.com/nodesource/distributions#enterprise-linux-based-distributions
-
RUN yum -y install nodejs
について- 先に取得したリポジトリからyumを用いてNode.jsをインストールしている。
- これはこの次に実行するnpmコマンド実行のため。
-
RUN npm i -g n
について- Node.jsのバージョンを管理してくれるツール「n」をインストールしている。
- このコマンドそのものは当該のツールのGithubに記載されている。
- https://github.com/tj/n#installation
-
RUN n 14
について- 「n」を用いてNode.jsのバージョン14をインストールしている。
- https://github.com/tj/n#installing-nodejs-versions