0

I am trying to build a docker file and I am getting an error "failed to compute cache key: "/source" not found: not found"

This is my directory structure

myapp

 - deployment

   -- Dockerfile

 
 - source

   -- public

   -- view

   -- app.js

package.json

package-lock.json

This is my docker file

FROM node:18-alpine

ENV NODE_ENV=production

WORKDIR /usr/src/app

COPY ../package*.json /usr/src/app/

RUN npm install --production --silent 

COPY ../source /usr/src/app/dist

ENV PORT 3001

EXPOSE ${PORT}

ENV SERVICE_VERSION 1.0.2

ENV NODE-ENV=production

CMD ["node", "dist/app.js"]
user2570135
  • 2,669
  • 6
  • 50
  • 80
  • You can't ever `COPY ../anything` into the container; everything you `COPY` in must be in or beneath the directory passed as an argument to `docker build. I might just move the Dockerfile up to the top-level directory next to your `package.json` and adjust the paths accordingly. – David Maze Mar 23 '23 at 11:16

1 Answers1

2

stay in root of your project(myapp directory) and use --file instead of using ../ for your files.
so you will run your build command like this:

cd myapp
docker build -t image:tag --file deployment/Dockerfile .

you also need to change your Dockerfile to:

FROM node:18-alpine

ENV NODE_ENV=production

WORKDIR /usr/src/app

COPY package*.json /usr/src/app/

RUN npm install --production --silent 

COPY source /usr/src/app/dist

ENV PORT 3001

EXPOSE ${PORT}

ENV SERVICE_VERSION 1.0.2

# You have typo in NODE_ENV ( used - instead of _ )
#ENV NODE-ENV=production

ENV NODE_ENV=production

CMD ["node", "dist/app.js"]
Yaser Kalali
  • 730
  • 1
  • 6