简体   繁体   中英

yarn install error Couldn't find a package.json during Docker build

Yarn version: 0.21.2

Nodejs version: 6.9 and 4.7

When running yarn locally it works

When running npm install it works

When running yarn install Dockerfile ( docker build . ) it fails with: error Couldn't find a package.json file in "/root/.cache/yarn/npm-readable-stream-2.2.2-a9e6fec3c7dda85f8bb1b3ba7028604556fc825e"

I have absolutely no idea why.

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 is installed this way in the Dockerfile RUN curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.21.2 ENV PATH /root/.yarn/bin:$PATH RUN curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.21.2 ENV PATH /root/.yarn/bin:$PATH

When you build a docker image, no files are copied automatically in the docker image despite that are part of the docker build context . (depends also of your .dockerignore file configuration if you have any). To add files from the docker context to your docker image you can do it explicitly with running commands like ADD or COPY.

Below an example of dockerfile:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM