When I created a Docker image from an app developed with Nuxt.js, I got the error "** error Couldn't find the binary git **".
The source code of the Dockerfile where the error actually occurred is as follows.
FROM node:10.15.1-alpine as builder
WORKDIR /app
COPY . /app
RUN yarn install --production
RUN yarn build
FROM node:10.15.1-alpine
WORKDIR /app
COPY --from=builder /app /app
CMD ["yarn", "start"]
Reference: https://qiita.com/arthur_foreign/items/fca369c1d9bde1701e38
The error log looks like this: (I was supposed to push the image to GCR)
$ docker build -t gcr.io/${PROJECT_ID}/app_name:v1 .
Sending build context to Docker daemon 157.9MB
Step 1/9 : FROM node:10.15.1-alpine as builder
---> xxxxxxxxxx
Step 2/9 : WORKDIR /app
---> Running in xxxxxxxxxx
Removing intermediate container 0eb38e4dfdc1
---> xxxxxxxxxx
Step 3/9 : COPY . /app
---> xxxxxxxxxx
Step 4/9 : RUN yarn install --production
---> Running in xxxxxxxxxx
yarn install v1.13.0
[1/4] Resolving packages...
[2/4] Fetching packages...
error Couldn't find the binary git
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn install --production' returned a non-zero code: 1
As you can see in the title and heading, you're getting the error ʻerror Couldn't find the binary git`.
Exactly the same error was posted on teratail.
Reference: https://teratail.com/questions/179483
It seems that Git is crazy to see the best answer and solution report of teratail.
Perhaps teratail is a local operation, so let's match it with the Dockerfile.
If it doesn't work with Docker, you need to put Git in ʻapk, the package manager for ʻalpine.
Therefore, let's make the Dockerfile as follows.
FROM node:10.15.1-alpine as builder
WORKDIR /app
COPY . /app
RUN apk update && \
apk add git
RUN yarn install --production
RUN yarn build
FROM node:10.15.1-alpine
WORKDIR /app
COPY --from=builder /app /app
CMD ["yarn", "start"]
Then, the Docker image will be created successfully.
Successfully built xxxxxxxxxxxx
Successfully tagged gcr.io/gke_project_name/app_name:v1