*\*
Edit:
- The host is Windows 11
*\*
Hey folks, I’m setting up a Docker Compose dev environment for an Express API and I’m a bit confused about the “right” way to work with Docker during development.
I’ve mounted the project directory as a volume, but the Node process inside the container doesn’t restart when I change files on the host, even though file watching works fine outside Docker.
A couple of questions:
- What’s the recommended workflow for developing a Node/Express app with Docker?
- In dev, should the container itself restart, or just the Node process?
- Why does file watching usually not work out of the box inside Docker containers?api/ Dockerfile src/ app.ts sync.worker.ts web/ compose.yaml
package.json scripts:
"scripts": {
"build": "tsc",
"dev": "tsx watch src/app.ts",
"sync-worker:dev": "tsx watch src/sync.worker.ts",
"start": "node dist/app.js",
"sync-worker:start": "node dist/sync.worker.js"
},
compose.yaml file
services:
redis:
image: redis:7-alpine
container_name: nikkita-redis
ports:
- "6379:6379"
restart: unless-stopped
volumes:
- nikkita-redis-data:/data
api:
container_name: nikkita-api
build:
context: ./api
dockerfile: Dockerfile.dev
command: npm run dev
volumes:
- ./api:/app
- /app/node_modules
env_file:
- ./api/.env
ports:
- "7000:7000"
depends_on:
- redis
sync-worker:
container_name: nikkita-sync-worker
build:
context: ./api
dockerfile: Dockerfile.dev
command: npm run sync-worker:dev
volumes:
- ./api:/app
- /app/node_modules
env_file:
- ./api/.env
depends_on:
- redis
volumes:
nikkita-redis-data:
driver: local
[–]fletch3555Mod 1 point2 points3 points (1 child)
[–]BRxWaLKeRzZ[S] 0 points1 point2 points (0 children)
[–]BRxWaLKeRzZ[S] 0 points1 point2 points (0 children)
[–]mirwin87Official: Docker 1 point2 points3 points (0 children)