I have a problem.
Build project in docker and have error. That docker on npm install not found ppackage.json
Dockerfile
FROM node
#copy source
COPY . /app
# Install deps
RUN cd /app && npm install
# Build
CMD npm run build
CMD [ "npm", "run", "start" ]
BUT IN DOCKER PACKAGE.JSON EXIST
npm ERR! code ENOENT
2023-07-16T10:00:25.897789910Z npm ERR! syscall open
2023-07-16T10:00:25.898344831Z npm ERR! path /package.json
2023-07-16T10:00:25.899843841Z npm ERR! errno -2
2023-07-16T10:00:25.901767270Z npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/package.json'
2023-07-16T10:00:25.901968559Z npm ERR! enoent This is related to npm not being able to find a file.
2023-07-16T10:00:25.902319000Z npm ERR! enoent
2023-07-16T10:00:25.904753122Z
2023-07-16T10:00:25.904888750Z npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-07-16T10_00_25_792Z-debug-0.log
2023-07-16T10:00:25.934642675Z
- Delete packagae-lock.json
- Rebuild container
>Solution :
I guess you need to change the cd into WORKDIR
add WORKDIR "/app"
and you have 2 CMD commands, which will only execute the latter one.
Am not quite sure, but I guess your Dockerfile should look like this
FROM node
COPY . /app
WORKDIR "/app"
RUN npm install
RUN npm run build
CMD [ "npm", "run", "start" ]