简体   繁体   中英

Strange Git Error on Docker NPM Install

I had a working Dockerfile until literally a day ago when it just seemed to break. I didn't make any changes to my dependencies - but I am getting the following error:

[91mnpm ERR! code ENOGIT
[0m
[91mnpm ERR! No git binary found in $PATH
npm ERR! 
npm[0m
[91m ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.
[0m
[91m
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-09-28T21_12_50_050Z-debug.log
[0m
Removing intermediate container be9d5bfe5521

The command '/bin/sh -c npm install' returned a non-zero code: 1

This is super strange because this wasn't happening before. I'm also attaching my Dockerfile. The things I've tried so far are adding git (third line), and also trying to export the path. Nothing seems to be working.

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y git

FROM node:alpine

RUN npm install sails -g
#RUN npm install git -g
#RUN export PATH="$HOME/usr/bin/git:$PATH"

RUN mkdir -p /service/app
WORKDIR /service/app

COPY package.json /service/app
RUN npm install

COPY . /service/app

EXPOSE 80

CMD NODE_ENV=production sails lift

One reason for this could be that you are using the slim version of node in your Dockerfile :

FROM node:8-slim

I presume this does not include git, because when I changed to the full version the error went away:

FROM node:8.11.2

Try the following:

RUN apk update && \
    apk add --update git && \
    apk add --update openssh

The git binary within the docker container becomes available at /usr/bin/git

I had the same issue. It was due to lack of git. Below is how it worked

FROM node:alpine
RUN apk add git
RUN npm install ...

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