3

I am trying to ignore every node_modules in every workspaces / sub folders.

The fact is : it is impossible to (really) ignore a folder by its name in a volume.

So there was this trick :

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

It works well for apps that have one single node_modules. But what if there is multiple one like in the bellow directory tree ?

project
|   node_modules/
|   docker-compose.yml
|   Dockerfile
|
└─── workspaces/
|   └─── client/
|       |   node_modules/
|   |
|   └─── server/
|       |   node_modules/

Do I need really need to mount every node_modules as a volume in my docker-compose.yml ?

volumes:
  - ./:/app
  - /app/node_modules
  - /app/workspaces/client/node_modules
  - /app/workspaces/server/node_modules

Or is there another better way ?

Mehdi
  • 7,204
  • 1
  • 32
  • 44
Anatole Lucet
  • 1,603
  • 3
  • 24
  • 43
  • I think you can add `node_modules` into `dockerignore` file – Dominik Matis Aug 25 '19 at 21:05
  • 1
    @DominikMatis According to [this post](https://stackoverflow.com/a/50745824/8990411) you cannot ignore what's inside a volume, because is it shared to the container after the build. As I said there's a solution but it isn't really viable when there is a lot of `node_modules` to ignore. – Anatole Lucet Aug 25 '19 at 21:09
  • 1
    I'm always thinking about `**/node_modules` but I'm on mobile so can't test it sorry – Dominik Matis Aug 25 '19 at 21:11
  • Dominik's solution may work, c.f. this reply: https://stackoverflow.com/a/56511833/1006854 – Mehdi Aug 26 '19 at 10:59
  • @Mehdi Maybe I am missing something but, if there is a file (let's call it `file.txt`) in one of the host's `node_modules` folder, it should works when the container is being build but right after when the container is started, the volume will share the host's `node_modules` to the container with the `file.txt` in it. Try it, then run a an `ls` with `docker exec` and you will see the file. But again, maybe I am missing something. – Anatole Lucet Aug 26 '19 at 11:07
  • There is a feature request opened [here](https://github.com/docker/compose/issues/6997) – Diego Jul 01 '20 at 20:15

1 Answers1

0

rewrite as "*node_modules"
hopefully it helps

rahul
  • 19
  • 2