My folder structure is like this
project/
-backend/
Dockerfile
package.json
- docker-compose.yml
My dockerfile looks like this
FROM node:14-alpine as base
WORKDIR /src
COPY ./package*.json /src
EXPOSE 3000
FROM base as dev
ENV NODE_ENV=development
RUN npm install -g nodemon && npm install
COPY . /
CMD ["npm run start:dev"]
just a simple dockerfile, nothing crazy
and my docker-compose like
version: '3'
services:
web:
build:
context: ./backend
target: dev
volumes:
- .:/src
command: npm run start:dev
ports:
- "3000:3000"
environment:
NODE_ENV: development
DEBUG: nodejs-docker-express:*
When I do docker-compose up an error shows up saying
web_1 | npm ERR! code ENOENT
web_1 | npm ERR! syscall open
web_1 | npm ERR! path /src/package.json
web_1 | npm ERR! errno -2
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/src/package.json'
web_1 | npm ERR! enoent This is related to npm not being able to find a file.
web_1 | npm ERR! enoent
web_1 |
web_1 | npm ERR! A complete log of this run can be found in:
web_1 | npm ERR! /root/.npm/_logs/2021-05-22T20_54_52_629Z-debug.log
This means that the package.json hasn't been copied I know. But what I don't know is how to fix it. I think the error is in the dockerfile but I coulnd't fix it
can someone tell me what I am doing wrong?
Try out by editing your docker compose, you have a problem in your volumes that is copying the hole project directory.
replace
volumes:
- .:/src
with
volumes:
- ./backend:/src
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With