3

This is the docker-compose file I have already set the folder to share by Virtual Box VM but it is still not working.

version: '3'
    services:
      postgres:
        image: 'postgres:latest'
        deploy:  
          restart_policy:  
            condition: on-failure  
            window: 15m  
      redis:
        image: 'redis:latest'
      nginx:
        restart: always
        build:
          dockerfile: Dockerfile.dev
          context: ./nginx
        ports:
          - '3050:80'  
      api:
        build:
          dockerfile: Dockerfile.dev
          context: ./server
        volumes:
          - /usr/src/app/node_modules
          - ./server:/usr/src/app
        environment:
          - REDIS_HOST=redis
          - REDIS_PORT=6379
          - PGUSER=postgres
          - PGHOST=postgres
          - PGDATABASE=postgres
          - PGPASSWORD=postgres_password
          - PGPORT=5432
      client:
        build:
          dockerfile: Dockerfile.dev
          context: ./client
        volumes:
          - /usr/src/app/node_modules
          - ./client:/usr/src/app
      worker:
        build:
          dockerfile: Dockerfile.dev
          context: ./worker
        volumes:
          - /usr/src/app/node_modules
          - ./worker:/usr/src/app 

I am running it on Windows 7 sp1. Whenever I run docker-compose up - I get an error:

api_1       | npm ERR! code ENOENT
api_1       | npm ERR! syscall open
api_1       | npm ERR! path /usr/src/app/package.json
api_1       | npm ERR! errno -2
api_1       | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/
app/package.json'
api_1       | npm ERR! enoent This is related to npm not being able to find a fi
le.
api_1       | npm ERR! enoent
api_1       |
api_1       | npm ERR! A complete log of this run can be found in:
api_1       | npm ERR!     /root/.npm/_logs/2020-05-28T04_06_56_121Z-debug.log
complex_api_1 exited with code 254

Thanks in advance, please help. I am trying to run a Fibonacci project from the Udemy course of Docker and Kubernetes complete guide. enter image description here

enter image description here

Each service has its own package.json and other files.

Server Docker File :

FROM node:alpine

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .


CMD ["npm", "run", "dev"]

Worker Docker File :

FROM node:alpine

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "dev"]

Client Docker File :

FROM node:alpine

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .


CMD ["npm", "run", "start"]
Harshit
  • 1,510
  • 19
  • 42
  • You should probably delete all of those `volumes:` blocks. That will let Docker run the code that's built into the image, instead of overwriting it. That "overwrite" behavior is leading to the "no such file or directory" error: whatever content is in your host directory isn't compatible with the layout in the image and you're hiding everything there. – David Maze May 28 '20 at 09:48
  • But if i Delete volume blocks then the project is not running properly as it is a dynamic project . – Deepesh Acharya May 28 '20 at 14:15
  • Reading better, we are following the same udemy course concurrently and we are at the same lesson (near 130) Try with the solution that I posted. It should works – Giacomo Brunetta May 28 '20 at 23:59
  • I tried but it is still not working i even shared the folder and added its path in oracle VM box but still it gives out the same error. – Deepesh Acharya May 29 '20 at 03:58
  • Share your console terminal also – Giacomo Brunetta May 29 '20 at 08:22
  • Put It on c/Users/YOURUSER, not in Users only!! – Giacomo Brunetta May 29 '20 at 08:41

2 Answers2

0

If you want to share data between containers

services:
  client:
    build:
      dockerfile: Dockerfile.dev
      context: ./client
    volumes:
      - datavolume:/usr/src/app/node_modules
      - ./client:/usr/src/app
  worker:
    build:
      dockerfile: Dockerfile.dev
      context: ./worker
    volumes:
      - datavolume:/usr/src/app/node_modules
      - ./worker:/usr/src/app 
volumes:
  datavolume: {}

Since it looks like your dev, I would suggest mount your workspace folder into container


services:
  client:
    build:
      dockerfile: Dockerfile.dev
      context: ./client
    volumes:
      - ./node_modules:/usr/src/app/node_modules
      - ./client:/usr/src/app
  worker:
    build:
      dockerfile: Dockerfile.dev
      context: ./worker
    volumes:
      - ./node_modules:/usr/src/app/node_modules
      - ./worker:/usr/src/app 

And better way is treating every service a standalone project. Each of them should own their self package.json and node_modules.

services:
  client:
    build:
      dockerfile: Dockerfile.dev
      context: ./client
    volumes:
      - ./client:/usr/src/app
  worker:
    build:
      dockerfile: Dockerfile.dev
      context: ./worker
    volumes:
      - ./worker:/usr/src/app 

In my opinion, it doesn't make sense to use same libraries in different project which in different purpose.

RammusXu
  • 1,180
  • 1
  • 7
  • 21
0

I had the same error! Actually I solved moving my project to /c/Users/currentUser from c/Program Files/Docker Toolbox. Maybe you have your project folder inside Program Files directory and not inside Users one, is It right? Try with this, Just Copy your project folder inside users and running your docker-compose from there. Let me know!

Giacomo Brunetta
  • 1,409
  • 3
  • 18
  • 38
  • Tried it but it is not working i tried running it in user/currentuser as well as in user folder but still it gives the same error exited with code 254 in all three services that use volumes. – Deepesh Acharya May 29 '20 at 03:51
  • Are you sure? We are doing the same course, same section and same error. Did you move in that folder in terminal using CD? Show me your terminal – Giacomo Brunetta May 29 '20 at 07:51
  • I've seen you screenshot. You posted your project in Users, you have to Place It on Users/yourUser !! – Giacomo Brunetta May 29 '20 at 08:40