问题
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/
WORKDIR /tmp
RUN bundle install
WORKDIR /sapco
COPY . /sapco
# Get yarn and install global required packages
RUN yarn global add mjml
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
I build this with docker build -f Dockerfile.dev .
I get the following error:
=> [internal] load build definition from Dockerfile.dev 0.0s
=> => transferring dockerfile: 504B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for docker.io/library/ruby:2.7.2 1.2s
=> CACHED [1/8] FROM docker.io/library/ruby:2.7.2@sha256: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'
回答1:
The issue is that yarn is the same name for another binary provided by cmdtest
I eventually traced it down to https://github.com/yarnpkg/yarn/issues/2821
and resolved my issue with this command to run in the Dockerfile.
apt remove -y cmdtest
apt remove -y yarn
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 update
apt install yarn
来源:https://stackoverflow.com/questions/65865361/install-yarn-global-on-docker-file