I am trying to run a simple react app using Dockerfile and docker-compose. However when I run the command docker-compose up, it fails with error that package.json doesn't exist. I guess the docker volume mount is somehow overwriting this file.
Can someone please tell me any workaround to it.
Dockerfile
FROM node:alpine
WORKDIR /apps
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","run","start"]
Docker-compose.yml
version: '3'
services:
react-app:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- /apps/node_modules
- ./:/apps
Output
docker-compose up --build
Building react-app
Step 1/6 : FROM node:alpine
---> ebbf98230a82
Step 2/6 : WORKDIR /apps
---> Using cache
---> 52ab3e742158
Step 3/6 : COPY package.json .
---> Using cache
---> b88a10e48c6f
Step 4/6 : RUN npm install
---> Using cache
---> 1da097307540
Step 5/6 : COPY . .
---> Using cache
---> c748991eb661
Step 6/6 : CMD ["npm","run","start"]
---> Using cache
---> e138b3c17689
Successfully built e138b3c17689
Successfully tagged frontend_react-app:latest
Starting 86e0c20b7955_frontend_react-app_1 ... done
Attaching to 86e0c20b7955_frontend_react-app_1
86e0c20b7955_frontend_react-app_1 | npm ERR! path /apps/package.json
86e0c20b7955_frontend_react-app_1 | npm ERR! code ENOENT
86e0c20b7955_frontend_react-app_1 | npm ERR! errno -2
86e0c20b7955_frontend_react-app_1 | npm ERR! syscall open
86e0c20b7955_frontend_react-app_1 | npm ERR! enoent ENOENT: no such file or directory, open '/apps/package.json'
86e0c20b7955_frontend_react-app_1 | npm ERR! enoent This is related to npm not being able to find a file.
86e0c20b7955_frontend_react-app_1 | npm ERR! enoent
86e0c20b7955_frontend_react-app_1 |
86e0c20b7955_frontend_react-app_1 | npm ERR! A complete log of this run can be found in:
86e0c20b7955_frontend_react-app_1 | npm ERR! /root/.npm/_logs/2019-02-12T14_36_59_257Z-debug.log
86e0c20b7955_frontend_react-app_1 exited with code 254
Folder Structure
--node_modules
--package.json
--Dockerfile.dev
--Docker-compose.yml
EDIT---
Trying to make my app react to changes in the source code without the need to rebuild the image. For this I need this bind mount to work.