Reputation: 121
I am trying to run a create-react-app inside of a docker container and automate docker build/run with docker-compose to eventually add other containers like a backend + db. Running docker-compose in the local folder works properly but setting the context to the folder and running it in the parent directory results in an error.
I have tried to get the container to list the current files so I can see if package.json is properly being copied over but ls and bash aren't in path of the node image or container so they won't run properly.
docker-compose.yaml
version: '3.5'
services:
dashboard-serve:
container_name: dashboard
build:
context: ./React-Frontend
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- '3001:3000'
environment:
- NODE_ENV=development
dockerfile
FROM node:12.2.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install [email protected] -g
# start app
CMD ["npm", "start"]
It runs and outputs an error that it cannot find package.json
dashboard | npm ERR! path /app/package.json
dashboard | npm ERR! code ENOENT
dashboard | npm ERR! errno -2
dashboard | npm ERR! syscall open
dashboard | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
dashboard | npm ERR! enoent This is related to npm not being able to find a file.
dashboard | npm ERR! enoent
dashboard |
dashboard | npm ERR! A complete log of this run can be found in:
dashboard | npm ERR! /root/.npm/_logs/2019-07-30T15_55_23_780Z-debug.log
dashboard exited with code 254
Upvotes: 3
Views: 1686
Reputation: 4790
You must copy your files into the Docker container. Currently , you're only copying the package.json
file.
FROM node:12.2.0-alpine
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY ./React-Frontend/package.json /app/package.json
RUN npm install
RUN npm install [email protected] -g
# Copy files into Docker container
COPY ./React-Frontend /app
# start app
CMD ["npm", "start"]
Upvotes: 1