Gabriel
Gabriel

Reputation: 163

No such file or directory : Docker-compose up

I dockerized my mean application with docker-compose. This works fine. Now I try to use "volumes" so that my angular app (with ng serve) and my express app (with nodemon.js) auto-restart when coding. But identical error appears for both angular and express container :

angular_1   |
angular_1   | up to date in 1.587s
angular_1   | found 0 vulnerabilities
angular_1   |
angular_1   | npm ERR! path /usr/src/app/package.json
angular_1   | npm ERR! code ENOENT
angular_1   | npm ERR! errno -2
angular_1   | npm ERR! syscall open
angular_1   | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
angular_1   | npm ERR! enoent This is related to npm not being able to find a file.
angular_1   | npm ERR! enoent
angular_1   |
angular_1   | npm ERR! A complete log of this run can be found in:
angular_1   | npm ERR!     /root/.npm/_logs/2019-04-07T20_51_38_933Z-debug.log
harmonie_angular_1 exited with code 254

See my folder hierarchy :

-project
  -client
    -Dockerfile
    -package.json
  -server
    -Dockerfile
    -package.json
  -docker-compose.yml

Here's my Dockerfile for angular :

# Create image based on the official Node 10 image from dockerhub
FROM node:10

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package*.json /usr/src/app/

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app/

# Expose the port the app runs in
EXPOSE 4200

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

My Dockerfile for express :

# Create image based on the official Node 6 image from the dockerhub
FROM node:6

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package*.json /usr/src/app/

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app/

# Expose the port the app runs in
EXPOSE 3000

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

And finally my docker-compose.yml

version: '3' # specify docker-compose version

# Define the services/containers to be run
services:
  angular: # name of the first service
    build: client # specify the directory of the Dockerfile
    ports:
      - "4200:4200" # specify port forwarding
#WHEN ADDING VOLUMES, ERROR APPEARS!!!!!!
    volumes:
      - ./client:/usr/src/app

  express: #name of the second service
    build: server # specify the directory of the Dockerfile
    ports:
      - "3000:3000" #specify ports forwarding
    links:
      - database
#WHEN ADDING VOLUMES, ERROR APPEARS!!!!!!
    volumes:
      - ./server:/usr/src/app

  database: # name of the third service
    image: mongo # specify image to build container from
    ports:
      - "27017:27017" # specify port forwarding

Upvotes: 4

Views: 32710

Answers (2)

Damo
Damo

Reputation: 6433

I also had this error, it turned out to be an issue with my version of docker-compose. I'm running WSL on windows 10 and the version of docker-compose installed inside WSL did not handle volume binding correctly. I fixed this by removing /usr/local/bin/docker-compose and then adding an alias to the windows docker-compose executable alias docker-compose="/mnt/c/Program\ Files/Docker/Docker/resources/bin/docker-compose.exe"

If The above does not apply to you then try to update your version of docker-compose

Upvotes: 3

Nikola Bodrozic
Nikola Bodrozic

Reputation: 116

you volumes section should look like this:

    volumes:
      - .:/usr/app
      - /usr/app/node_modules

after mounting source folder node_modules in Docker container is 'overwritten' so you need to add the '/usr/app/node_modules'. Full tutorial with proper docker-compose.yml - https://all4developer.blogspot.com/2019/01/docker-and-nodemodules.html

Upvotes: 2

Related Questions