Install yarn global on Docker file

  dockerfile, ruby-on-rails, yarnpkg

I’m trying to get a global package recognized by yarn and the docker image.

FROM ruby:2.7.2

RUN apt-get update -qq && apt-get install -y nodejs libvips-tools yarn

# Install all gems first.
# This hits the warm cache if unchanged so bundling is faster.
COPY Gemfile* /tmp/
RUN bundle install

WORKDIR /sapco
COPY . /sapco

# Get yarn and install global required packages
RUN yarn global add mjml


# Start the main process.
CMD ["rails", "server", "-b", ""]

I build this with docker build -f .

I get the following error:

 => [internal] load build definition from                                                                                                                                                   0.0s
 => => transferring dockerfile: 504B                                                                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                                                                          0.0s
 => => transferring context: 35B                                                                                                                                                                           0.0s
 => [internal] load metadata for                                                                                                                                              1.2s
 => CACHED [1/8] FROM[email protected]:abe7034da4092958d306c37aded76a751ea9d35d5c90d1ad9e92290561bd5f3f                                                                                 0.0s
 => [internal] load build context                                                                                                                                                                          0.4s
 => => transferring context: 220.47kB                                                                                                                                                                      0.4s
 => [2/8] RUN apt-get update -qq && apt-get install -y nodejs libvips-tools yarn                                                                                                                          38.2s
 => [3/8] COPY Gemfile* /tmp/                                                                                                                                                                              0.1s
 => [4/8] WORKDIR /tmp                                                                                                                                                                                     0.0s
 => [5/8] RUN bundle install                                                                                                                                                                             292.6s
 => [6/8] WORKDIR /sapco                                                                                                                                                                                   0.0s
 => [7/8] COPY . /sapco                                                                                                                                                                                    0.5s
 => ERROR [8/8] RUN yarn global add mjml                                                                                                                                                                   0.7s
 > [8/8] RUN yarn global add mjml:
#12 0.567 Parsing scenario file global
#12 0.568 ERROR: [Errno 2] No such file or directory: 'global'

Source: Dockerfile Questions