Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 722
Jeff Avatar asked Feb 22 '17 15:02

Jeff


1 Answers

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
like image 70
Mathieu Seiler Avatar answered Sep 23 '22 11:09

Mathieu Seiler