在 Docker 文件上安装 yarn global
Posted
技术标签:
【中文标题】在 Docker 文件上安装 yarn global【英文标题】:Install yarn global on Docker file 【发布时间】:2021-04-28 02:42:29 【问题描述】:我正在尝试获取由 yarn 和 docker 映像识别的全局包。
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"]
我用docker build -f Dockerfile.dev .
构建这个
我收到以下错误:
=> [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'
【问题讨论】:
这能回答你的问题吗? Yarn install command error No such file or directory: 'install' TL;DR:这不是你想的那样。 【参考方案1】:问题是纱线与cmdtest
提供的另一个二进制文件同名
我最终将其追溯到 https://github.com/yarnpkg/yarn/issues/2821
并解决了我在 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
【讨论】:
以上是关于在 Docker 文件上安装 yarn global的主要内容,如果未能解决你的问题,请参考以下文章