← Back to all fixes
Docker build using stale cache after code change
The Issue
You changed app code, rebuilt the image, but the running container still serves old behaviour.
Root Cause
Docker caches each layer. If `COPY` comes before `RUN npm install`, any code change busts all layers. But if `COPY . .` is too early and your Dockerfile is ordered badly, you may be copying stale files or running with an old base.
How to Fix
Order Dockerfile correctly: COPY package*.json first, RUN npm install, then COPY . . — so code changes only bust the last layerForce a full rebuild when needed: `docker build --no-cache -t myapp .`Confirm the new image is being used: `docker inspect <container> | grep Image`Make sure you stopped the old container before running the new one