LoginSignup
29
26

More than 5 years have passed since last update.

Dockerでnodeをバージョン指定してインストールする

Last updated at Posted at 2019-03-20

環境

macOS Mojave 10.14.3
Ruby 2.4.0
Node.js 9.2.0
Docker

Curlでインストール

チーム開発では、ローカルに開発環境を構築する際、nodeのバージョンを合わせる必要があるかと思います。
今回はv9.2.0が必要でした。
Dockerfileにnodeのインストールを記述したいのですが、


RUN curl -sL https://deb.nodesource.com/setup_9.X | sudo -E bash -
RUN sudo apt-get install -y nodejs

上記のような方法ではバージョンが細かく指定できずに困りました。
調べたところ、n packageを使用してインストールする方法があるようです。

n packageを使用してのインストール

RUN apt-get install -y nodejs npm
RUN npm install n -g 
RUN n 9.2.0

n {version}のように、バージョンが指定できます。

完成

最終的に下記のようなDockerfileを作成しました。

FROM ruby:2.4.0
RUN apt-get update -qq && apt-get install -y build-essential libxslt-dev libxml2-dev cmake
RUN apt-get install -y nodejs npm && npm install n -g && n 9.2.0
RUN mkdir /app
WORKDIR /app
COPY ./src/Gemfile /app/Gemfile
COPY ./src/Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY ./src /app

参考

Ubuntuに最新のNode.jsを難なくインストールする

29
26
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
29
26