I'm using Docker Compose for a React/Express application.
Dockerfile for the server:
FROM node:latest
WORKDIR /app/server
COPY package.json /app/server
COPY package-lock.json /app/server
RUN npm install
COPY . /app/server
CMD [ "npm", "run", "dev" ]
Dockerfile for the client:
FROM node:latest
WORKDIR /app/client
COPY package.json /app/client
COPY package-lock.json /app/client
RUN npm install
COPY . /app/client
CMD [ "npm", "start" ]
And my docker-compose file:
version: '3'
services:
server:
build: ./server
expose:
- "3001"
ports:
- "3001:3001"
volumes:
- ./server/src/:/app/server
command: npm run dev
tty: true
client:
build: ./client
expose:
- "3000"
ports:
- "3000:3000"
volumes:
- ./client/src/:/app/client
links:
- server
command: npm run start
tty: true
After running "docker-compose up" the server crashes:
npm ERR! Missing script: "dev"
However, I DO have a "dev" script inside my package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.js",
"start": "node index.js"
},
What is the problem here? The script is there. Is there something wrong with my Docker files? "npm run dev" works just fine without Docker.
Thanks!