简体   繁体   中英

Docker compose not properly copying files to run react app

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 react-scripts@3.0.1 -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

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 react-scripts@3.0.1 -g 

# Copy files into Docker container
COPY ./React-Frontend /app

# start app
CMD ["npm", "start"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM