Home > Net >  compose node container throws: npm ERR! enoent ENOENT: no such file or directory
compose node container throws: npm ERR! enoent ENOENT: no such file or directory

Time:01-20

I got this error in docker:

npm ERR! enoent ENOENT: no such file or directory, open 
'/home/dan/repos/test_11/wp-content/themes/twentytwentyone/package.json'

This is my docker-compose.yml file:

version: "3.9"
services:
  npm:
    image: node:16.13.2
    container_name: dan_npm
    volumes:
      - "./app:/home/dan/repos/test_11/wp-content/themes/twentytwentyone"
    working_dir: "/home/dan/repos/test_11/wp-content/themes/twentytwentyone"
    entrypoint: [ 'npm', 'start' ]

What do I miss?

Image from project folder tree

CodePudding user response:

Your problem is that you mount the /app and everything inside at the end of the path inside the container. So you are repeating the path.

By doing this.

volumes:
  # mounts app and everything inside at the location after the colon
  - ./app:/home/dan/repos/test_11/wp-content/themes/twentytwentyone

The final path, inside the container, will be this.

/home/dan/repos/test_11/wp-content/themes/twentytwentyone/wp-content/themes/twentytwentyone/

I would suggest mounting something like this.

working_dir: /twentytwentyone
volumes:
  # mount only the relevant folder (the last one) inside /app 
  # to some location, not as deeply nested for convinience
  - ./app/wp-content/themes/twentytwentyone:/twentytwentyone
  •  Tags:  
  • Related