Home > Enterprise >  I am learning Docker & Kubernetes and have just started my first project. When I attempt to build my
I am learning Docker & Kubernetes and have just started my first project. When I attempt to build my

Time:10-07

I have built a structure for a microservice app. auth is the first Dockerfile I have made and as far as I can tell is not building.

C:\Users\geeks\Desktop\NorthernHerpGeckoSales\NorthernHerpGeckoSales\auth>docker build -t giantgecko/auth .
[ ] Building 0.1s (9/9) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                    0.0s
 => => transferring dockerfile: 206B                                                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                       0.0s
 => => transferring context: 53B                                                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/node:alpine                                                                                                                                                                          0.0s
 => [1/5] FROM docker.io/library/node:alpine                                                                                                                                                                                            0.0s
 => [internal] load build context                                                                                                                                                                                                       0.0s
 => => transferring context: 479B                                                                                                                                                                                                       0.0s
 => [2/5] WORKDIR /app                                                                                                                                                                                                                  0.0s
 => CACHED [3/5] COPY package.json .                                                                                                                                                                                                    0.0s
 => CACHED [4/5] RUN npm install                                                                                                                                                                                                        0.0s
 => ERROR [5/5] COPY /Users/geeks/Desktop/NorthernHerpGeckoSales/NorthernHerpGeckoSales/auth .                                                                                                                                          0.0s
------
 > [5/5] COPY /Users/geeks/Desktop/NorthernHerpGeckoSales/NorthernHerpGeckoSales/auth .:
------
failed to compute cache key: "/Users/geeks/Desktop/NorthernHerpGeckoSales/NorthernHerpGeckoSales/auth" not found: not found

CodePudding user response:

Could you share more details on your Dockerfile? But based on your error, it seems it stopped on the COPY stage. You need to provide the <source> and the <destination>. Here's an example based on your error:

WORKDIR /app
COPY /Users/geeks/Desktop/NorthernHerpGeckoSales/NorthernHerpGeckoSales/auth /app/auth

By default, all files will be copied under the WORKDIR

you can checkout official documentation of Dockerfile here https://docs.docker.com/engine/reference/builder/#copy

CodePudding user response:

I was able to resolve this by changing my Dockerfile to:

FROM node:alpine

WORKDIR /app
COPY package.json .
RUN npm install
COPY . .

CMD ["npm", "start"]

The fix came after I changed COPY from the absolute path to . ., and cleared the npm cache with npm cache clean -f.

  • Related