1

Hello i have the following setup docker:

docker-compose.yml:

version: "3"

services:
  micro-hr:
    build: ./backend/micro-hr
    entrypoint: ./backend/micro-hr/.docker/entrypoint.sh
    container_name: micro-hr
    environment:
      - CHOKIDAR_USEPOLLING=true
    ports:
      - 3001:3000
    volumes:
      - .:/home/node/app

dockerfile:

FROM node:12.14.0-alpine3.11

RUN apk add --no-cache bash git

RUN touch /home/node/.bashrc | echo "PS1='\w\$ '" >> /home/node/.bashrc

RUN npm config set cache /home/node/app/.npm-cache --global

WORKDIR /home/node/app

COPY --chown=node:node . ./

COPY package*.json .env ./

USER node

and entrypoint.sh

#!/bin/bash

npm config set cache /home/node/app/.npm-cache --global

cd /home/node/app

npm install
npm run start:dev

but i got this errors on docker-compose up:

micro-hr              | npm WARN saveError ENOENT: no such file or directory, open '/home/node/app/package.json'
micro-hr              | npm WARN enoent ENOENT: no such file or directory, open '/home/node/app/package.json'
micro-hr              | npm WARN app No description
micro-hr              | npm WARN app No repository field.
micro-hr              | npm WARN app No README data
micro-hr              | npm WARN app No license field.
micro-hr              | 
micro-hr              | up to date in 1.154s
micro-hr              | found 0 vulnerabilities
micro-hr              | 
micro-hr              | npm ERR! code ENOENT
micro-hr              | npm ERR! syscall open
micro-hr              | npm ERR! path /home/node/app/package.json
micro-hr              | npm ERR! errno -2
micro-hr              | npm ERR! enoent ENOENT: no such file or directory, open '/home/node/app/package.json'
micro-hr              | npm ERR! enoent This is related to npm not being able to find a file.
micro-hr              | npm ERR! enoent 
micro-hr              | 
micro-hr              | npm ERR! A complete log of this run can be found in:
micro-hr              | npm ERR!     /home/node/app/.npm-cache/_logs/2020-09-01T01_00_33_229Z-debug.log

I had suspected it was in relation to the node user, but I tested it without and it was not i got this with docker-compose log.

Ming
  • 1,349
  • 4
  • 13
  • 36
  • 1
    Your `volumes:` are overwriting the code that's built into the image with content from the host system, but that doesn't match what's in the image. If you're trying to actively develop your application you might find it easier to install Node and have an actual local development environment, than to try to simulate it with Docker. – David Maze Sep 01 '20 at 01:47
  • 1
    does this helps : https://stackoverflow.com/questions/54884565/docker-compose-fails-to-start-with-npm-err-enoent-enoent-no-such-file-or-direc – Jatin Mehrotra Sep 01 '20 at 01:47
  • @David Maze yeah, i know, is only from training, i fix, thank u. – Ming Sep 01 '20 at 02:11
  • @Jatin Mehrotra thank u bro – Ming Sep 01 '20 at 02:12
  • 1
    Glad to help you :) – Jatin Mehrotra Sep 01 '20 at 02:47
  • @JatinMehrotra if you want to answer the question I vote as the correct answer Thanks a lot. – Ming Sep 01 '20 at 10:11
  • 1
    I will post it as an answer, thanks mate. – Jatin Mehrotra Sep 01 '20 at 13:15
  • 1
    Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220800/discussion-between-jatin-mehrotra-and-gabriel-costa). – Jatin Mehrotra Sep 01 '20 at 13:20

1 Answers1

1

Your docker-compose.yml says

volumes:
      - .:/home/node/app

Remove these two lines, build application locally (without Docker), and only build the Docker image when you are deploying it.

for further explanation refer this docker-compose fails to start with npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'

Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67