0

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

1 Answer 1

1

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"]
Sign up to request clarification or add additional context in comments.

3 Comments

Halil error is Step 4/7 : RUN npm ci ---> Running in 00e1df66522d npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2020-10-25T20_45_01_752Z-debug.log
I will change the post with the insertion and the new error.
if you don't have package-lock.json, you should use npm install instead of using npm ci. Change with npm install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.