LoginSignup
2
2

More than 5 years have passed since last update.

Rails用にruby-onbuildにyarnを追加してbuildするdockerfile

Posted at

Dockerイメージのruby:2.4-onbuildでRails5.1を動かすためのDockerfileサンプル。
ruby-onbuildにyarnを追加する情報が少なそうだったので書き残す。

ポイント

  1. ruby公式イメージはdebianベース
  2. yarn向けにnodejsのバージョンが足りないため現在の最新版node9を追加
  3. yarnリポジトリを追加してインストール

※依存関係の用意が不足しているとbuildエラーE: Unable to locate package yarn等が出る。

結果こんな感じ

Dockerfile
# WORKDIR = /usr/src/app
FROM ruby:2.4-onbuild

RUN bundle config --delete frozen \
 && apt-get update -qq && apt-get install -y build-essential \
 && curl -sL https://deb.nodesource.com/setup_9.x | bash - \
 && apt-get install -y nodejs \
 && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
 && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
 && apt-get update && apt-get install yarn \
 && rm -rf /var/lib/apt/lists/*

参照

Cannot install yarn from docker image ruby:2.3-slim · Issue #2888 · yarnpkg/yarn
https://github.com/yarnpkg/yarn/issues/2888

Installation | Yarn
https://yarnpkg.com/lang/en/docs/install/

Installing Node.js via package manager | Node.js
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

2
2
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
2
2