You edit NestJS code but the container keeps running the old version
Code changes on the host do not show up in the running containerShort answer
Hot reload in a container needs three things: the dev stage of your Dockerfile must be the one that runs, your edited files must reach the container, and the container must run a watch command. Check build.target in Compose first, then add a develop.watch rule that syncs src and rebuilds on package.json.
Fix it fast
1Find out which cause you have
Print the command the running container actually uses and the image stage it was built from. If it is node dist/main, you are running the production stage, not a watcher.
docker compose config | grep -n -A4 "build:" docker compose top api2Match what you see, then jump to its fix
- 1
the process list shows node dist/main and no nest processCompose builds the last (production) stage of the multistage DockerfileFix - 2
The container logs show the first start only; saving a file produces no recompile lineYour edited files never reach the containerFix - 3
Dependencies missing or different right after you added a volume that maps . to /appA bind mount of the whole project hides the node_modules built in the imageFix
- 1
What does the error look like?
Code changes on the host do not show up in the running containernest start --watch prints nothing after a file is savedThe container starts the production command (node dist/main) even in development
Cause 1 of 3
Compose builds the last (production) stage of the multistage Dockerfile
1Check
Without a target, a multistage build produces the final stage. If your Dockerfile ends with a slim production stage, that is what runs.
grep -n "^FROM" Dockerfile
docker compose config | grep -n -B1 -A3 "target"2Fix
Name the development stage in the Dockerfile and tell Compose to build exactly that stage with build.target. Give that stage a CMD that starts the watcher.
# Dockerfile
FROM node:22 AS dev
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npx", "nest", "start", "--watch"]
# compose.yaml
services:
api:
build:
context: .
target: dev3Verify
Rebuild and check that the nest watcher is the running process.
docker compose up --build -d api
docker compose top apiConfirmed by docs.docker.com
Cause 2 of 3
Your edited files never reach the container
1Check
COPY puts a snapshot of the source into the image at build time. Later edits on the host are not seen unless you sync or mount them.
docker compose config | grep -n -E "watch|volumes"2Fix
Add a Compose watch rule that syncs src into the container, and a rebuild rule for package.json. Watch works only for services that use build, and the container user must be able to write to the target path.
services:
api:
build:
context: .
target: dev
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- node_modules/
- action: rebuild
path: package.json3Verify
Start in watch mode, save a file in src and read the container log.
docker compose up --watch
# in a second terminal
docker compose logs -f apiConfirmed by docs.docker.com
Cause 3 of 3
A bind mount of the whole project hides the node_modules built in the image
1Check
A bind mount hides whatever already exists at the target path in the container. Mounting your project folder over /app hides the dependencies that npm ci installed in the image and replaces them with the host folder.
docker compose config | grep -n -B2 -A4 "volumes"
docker compose exec api ls /app/node_modules | head2Fix
Stop mounting the whole project. Use a develop.watch sync rule that ignores node_modules/ (Compose documents this as the purpose of watch next to bind mounts) so dependencies stay the ones installed in the image.
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- node_modules/3Verify
Remove the volumes entry, recreate the container, and confirm the dependencies exist.
docker compose up --build --watch
docker compose exec api ls /app/node_modules | headConfirmed by docs.docker.com
How do I stop it coming back?
- Keep one named dev stage in the Dockerfile and set build.target in the Compose file that developers use.
- Use develop.watch with a rebuild rule for package.json so new dependencies reach the image.
- Keep node_modules out of every sync or mount path.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Servers
NestJS cannot resolve the host name redis when using Docker Compose
code: 'ENOTFOUND'
The name redis only exists inside the Compose network, as the service name.
3 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
bcrypt_lib.node: invalid ELF header inside a Docker container
Error: /app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: invalid ELF header
bcrypt is a compiled addon, so the file in node_modules only runs on the operating system it was installed on.
3 causes, each with a fixServers
cdk deploy fails in a GitLab job with spawnSync docker ENOENT
code: 'ENOENT'
ENOENT means the operating system found no docker program to run.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
Node.js app says Cannot find module only when it runs under Docker Compose
The same image starts fine with docker run but fails with docker compose up
The image installed node_modules, but a Compose volume mounted over the app folder hides them.
3 causes, each with a fix