Why Isn’t My Node Modules Folder Syncing with Docker on Windows?

0
26
Asked By CuriousCoder987 On

I'm trying to set up a Deno app using Docker Compose along with MongoDB and Mongo Express. Here's how my Docker Compose file looks:

```yaml
services:
mongo:
...
mongo-express:
...
deno-app:
build:
dockerfile: ./docker/deno/Dockerfile
context: .
volumes:
- .:/app
- node_modules:/app/node_modules
ports:
- "8000:8000"
- "5173:5173"
environment:
- DENO_ENV=development
command: ["deno", "run", "dev", "--host"]
```

And here's my Dockerfile:

```dockerfile
FROM denoland/deno:latest

RUN ["apt", "update"]
RUN ["apt", "install", "npm", "-y"]

COPY package.json /app/package.json

WORKDIR /app

RUN ["npm", "i", "-y"]
```

My project structure is:
```
-docker/
-deno/
-Dockerfile
-src/
-package.json
-docker-compose.yml
```

When I run `docker-compose build`, everything works fine, but I can't find the `node_modules` folder on my host machine. This is an issue because my IDE can't resolve the modules without that folder being visible.

I'm running this on Windows. Can anyone help with adjusting my Compose file to fix this issue? Let me know if you need more details. Thanks!

2 Answers

Answered By DockerDude42 On

It sounds like you're using a Docker volume, which can sometimes hide files in the Docker directory instead of syncing with your host. Consider switching to a bind mount for the `node_modules` folder. This way, it'll be accessible directly from your host. Just check the Docker documentation on bind mounts for details!

CuriousCoder987 -

Thanks for that advice! I actually tried using a bind mount already, but I still can't see the `node_modules` folder on my host. Here's the modified section of my compose file:

```yaml
volumes:
- .:/app
- type: bind
source: node_modules
target: /app/node_modules
```

Is there something I'm missing?

Answered By TechWhiz918 On

Another thing you might want to check is whether Docker has permission to write to the directory where your project is. Windows can be a bit finicky with file permissions for Docker. Make sure that you are giving access to the necessary folders when you set up Docker Desktop.

CuriousCoder987 -

Good point! I'll check the folder permissions on Windows to see if that's causing the issue. Thanks for the tip!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.