I created a Dockerfile to build my Angular application with Nx:
FROM node:alpine3.19 AS builder
WORKDIR /app
RUN apk update && apk add git
COPY .git .git
COPY yarn.lock package.json .npmrc ./
RUN yarn --ignore-scripts --frozen-lockfile
COPY . .
RUN if [ -d .git ]; then echo ".git directory exists"; else echo ".git directory does not exist"; fi
RUN yarn nx format:check
However, the command yarn nx format:check
fails because the .git
folder is not copied and does not exist. (the command is uses git diff under the hood)
To fix this, I added COPY .git .git
to the Dockerfile, but then I got an error:
#10 [builder 4/11] COPY .git .git
#10 ERROR: failed to calculate checksum of ref 89226611-c9a1-4907-b9f1-63100dae5a7c::z0tocv9x9pdgswr96d0866cfu: "/.git": not found
------
> [builder 4/11] COPY .git .git:
------
Dockerfile:7
--------------------
5 | RUN apk update && apk add git
6 |
7 | >>> COPY .git .git
8 |
9 | COPY yarn.lock package.json .npmrc ./
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 89226611-c9a1-4907-b9f1-63100dae5a7c::z0tocv9x9pdgswr96d0866cfu: "/.git": not found
Why is this happening, and how can I solve it?