skip to Main Content

I am trying to Dockerise a React app, but when it reaches the command to install npm it throws an error.

My Dockerfile contains:

# pull official base image
FROM node:12.6.0-alpine


# set working directory
RUN mkdir /app
COPY . /app
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH

RUN yarn

# start app
CMD ["npm", "start"]

The error is this when it reaches the command to run npm install or yarn:

[5/5] RUN yarn:                                                                                                                             
#9 0.725 yarn install v1.16.0                                                                                                                  
#9 0.789 info No lockfile found.                                                                                                               
#9 0.801 warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.   
#9 0.809 [1/4] Resolving packages...
#9 1.507 warning [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
#9 8.363 warning formik > create-react-context > fbjs > [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
#9 40.35 error Couldn't find the binary git
#9 40.35 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
------
executor failed running [/bin/sh -c yarn]: exit code: 1

3

Answers


  1. #9 40.35 error Couldn’t find the binary git

    Solution: install git in your docker image.

    Login or Signup to reply.
  2. Install git in your image like this

    FROM node:12.6.0-alpine
    RUN apk update && apk add git
    
    # set working directory
    RUN mkdir /app
    COPY . /app
    WORKDIR /app
    ENV PATH /app/node_modules/.bin:$PATH
    
    RUN yarn
    
    # start app
    CMD ["npm", "start"]
    
    Login or Signup to reply.
  3. the package was not installing due to admin authorization issues so I use force command to install and it worked

    RUN npm install --force
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search