0
0

More than 1 year has passed since last update.

Docker AmazonLinux2のコンテナにNode.jsを入れている部分の処理を紐解いてみた

Last updated at Posted at 2022-01-23

概要

  • 他の方が作ってくれたの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 -について

  • 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について

参考文献

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