[Ruby] install yarn inside docker image

less than 1 minute read

Background

When deploying a Rails application (v5.2.4) created using Docker to the production environment, when I tried to precompile assets, the following error was not able to be executed.

$docker-compose run web bundle exec rake assets:precompile RAILS_ENV=production
Starting excite-map_db_1 ... done
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/instal

Solution

Add the following to the Dockerfile

RUN curl https://deb.nodesource.com/setup_12.x | bash
RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add-
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update && apt-get install -y nodejs yarn postgresql-client

Reference

https://github.com/yarnpkg/yarn/issues/7329