Reputation: 117
I am putting a react application to use docker-compose. The Dockerfile file and the docker-compose.yml were created but an error is occurring to build the application.
Dockerfile
FROM node:8
WORKDIR /usr/src/app
RUN npm ci
EXPOSE 3000
# start app
CMD ["npm", "start"]
docker-compose.yml
version: "3.3"
services:
app:
container_name: react_app
build:
context: .
dockerfile: Dockerfile
volumes:
- ./app:/usr/src/app
- /usr/src/app/node_modules
ports:
- '3000:3000'
stdin_open: true
environment:
- NODE_ENV=development
The folder architecture is:
docker-compose.yml docker app/package.json app/src/
when executing the command docker-compose up -d --build the error below occurs.
Building app Step 1/5 : FROM node:8 ---> 8eeadf3757f4 Step 2/5 : WORKDIR /usr/src/app ---> Running in 1420513ebefb Removing intermediate container 1420513ebefb ---> f46f192dd592 Step 3/5 : RUN npm ci ---> Running in edb7041c8ba5 npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /usr/src/app/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/spa/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent
npm ERR! A complete log of this run can be found in: npm ERR!
/root/.npm/_logs/2020-10-25T19_38_16_569Z-debug.log ERROR: Service 'app' failed to build: The command '/bin/sh -c npm ci' returned a non-zero code: 254
Upvotes: 0
Views: 547
Reputation: 597
You have to copy your project files to the inside of the docker container. The below code will help to fix your problem.
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . .
EXPOSE 3000
# start app
CMD ["npm", "start"]
Upvotes: 1