gpt4 book ai didi

node.js - yarn 安装错误在 Docker 构建期间找不到 package.json

转载 作者:行者123 更新时间:2023-12-03 12:10:21 44 4
gpt4 key购买 nike

yarn 版本:0.21.2

Nodejs 版本:6.9 和 4.7

在本地运行 yarn 时,它可以工作

运行 npm install 时它可以工作

运行 yarn install Dockerfile ( docker build . ) 时失败: error Couldn't find a package.json file in "/root/.cache/yarn/npm-readable-stream-2.2.2-a9e6fec3c7dda85f8bb1b3ba7028604556fc825e"
我完全不知道为什么。

Step 16 : RUN yarn install
---> Running in 917c2b1b57fb
yarn install v0.21.2
[1/4] Resolving packages...
[2/4] Fetching packages...
error Couldn't find a package.json file in "/root/.cache/yarn/npm-readable-stream-2.2.2-a9e6fec3c7dda85f8bb1b3ba7028604556fc825e"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn install' returned a non-zero code: 1

Yarn 以这种方式安装在 Dockerfile 中
RUN curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.21.2
ENV PATH /root/.yarn/bin:$PATH

最佳答案

构建 docker 镜像时,不会在 docker 镜像中自动复制任何文件,尽管它们是 docker 构建上下文的一部分。 (也取决于您的 .dockerignore 文件配置,如果有的话)。要将文件从 docker 上下文添加到您的 docker 镜像,您可以通过运行诸如 ADD 或 COPY 之类的命令来明确地执行此操作。
下面是 dockerfile 的示例:

WORKDIR /app
COPY ["yarn.lock", "package.json", "./"]

# Install app dependencies
RUN yarn install --check-files --non-interactive --ignore-optional --frozen-lockfile

关于node.js - yarn 安装错误在 Docker 构建期间找不到 package.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42395519/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com