yarn install error在Docker构建期间找不到package.json

jef*_*f35 7 node.js docker yarnpkg

纱线版本:0.21.2

Nodejs版本:6.9和4.7

在本地运行纱线时它起作用

运行npm install时可以正常运行

当运行yarn安装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
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*ler 1

当您构建 docker 映像时,不会在 docker 映像中自动复制任何文件,尽管这些文件是 docker build context 的一部分。(还取决于您的 .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
Run Code Online (Sandbox Code Playgroud)