a month ago
I'm experiencing a persistent Docker build cache issue on Railway where the frontend build output is not being deployed despite successful builds.
Setup:
Multi-stage Dockerfile with fe (frontend), be (backend), and runtime stages
Frontend built with npm run build in fe stage, copied to runtime via COPY --from=fe /app/frontend/dist ./frontend/dist
GitHub auto-deploy from main branch
Problem:
Build logs show fe RUN npm run build executes successfully (14s, "built in 9.92s"), but runtime COPY --from=fe /app/frontend/dist ./frontend/dist shows "cached" (0ms). The live JS bundle does not contain new code even though GitHub has it.
What I've tried:
Added ARG BUILD_DATE to both fe and runtime stages, bumping the value on each deploy - fe stage rebuilds, but runtime COPY --from=fe is still cached
Set NO_CACHE=1 service variable and redeployed - still cached
Disconnected/reconnected GitHub repo (webhook was broken, now fixed)
Verified GitHub has new code via API, but live bundle doesn't
Evidence:
GitHub commit has setPostReplyTarget in frontend/src/components/FanBoard.tsx
Live /assets/index-*.js does NOT contain this function
Build log: fe RUN npm run build → 14s (not cached)
Build log: runtime COPY --from=fe → 0ms (cached)
How can I force Railway to invalidate the COPY --from layer cache? The ARG busting works for the fe stage but not for the COPY --from=fe in the runtime stage.
7 Replies
a month ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • about 1 month ago
a month ago
Try adding the --link flag to your COPY command, so it would be: COPY --link --from=fe /app/frontend/dist ./frontend/dist. This creates a standalone layer for the copied files, which should invalidate the cache for this layer. Also, make sure ARG BUILD_DATE is before the copy command, and not after it.
darseen
Try adding the `--link` flag to your COPY command, so it would be: `COPY --link --from=fe /app/frontend/dist ./frontend/dist`. This creates a standalone layer for the copied files, which should invalidate the cache for this layer. Also, make sure `ARG BUILD_DATE` is before the copy command, and not after it.
a month ago
Thanks for the suggestion! I tried it, but unfortunately it didn't work.
What I did:
Changed all COPY --from to COPY --link --from (frontend and backend)
Verified ARG BUILD_DATE is before the COPY commands in the runtime stage
Bumped BUILD_DATE and pushed, deployment succeeded
Result:
Build logs still show COPY --link --from=fe /app/frontend/dist as cached (0ms). The live JS bundle (/assets/index-Cmkzmq-4.js) still does NOT contain the new code, even though GitHub has it.
The --link flag doesn't seem to invalidate the cache on Railway's builder. Any other ideas?
a month ago
The builder might not have accepted the link flag; try adding # syntax=docker/dockerfile:1.4 as the first line in your dockerfile to ensure the builder accepts the --link flag. Also, it's worth checking your .dockerignore file to see if it's the cause of the problem.
darseen
The builder might not have accepted the link flag; try adding `# syntax=docker/dockerfile:1.4` as the first line in your dockerfile to ensure the builder accepts the `--link` flag. Also, it's worth checking your `.dockerignore` file to see if it's the cause of the problem.
a month ago
Tried adding # syntax=docker/dockerfile:1.4 as first line. Build succeeded, but live JS bundle still doesn't have new code. The COPY --link --from=fe still shows as cached in build logs.
I'm considering deleting the service and recreating it from scratch to clear all caches. Is this a reasonable approach, or is there a less drastic way?
a month ago
I'd suggest you spin up a new service and configure it, if all goes well, delete the old one. Just in case something goes wrong, you still have the original service.
darseen
I'd suggest you spin up a new service and configure it, if all goes well, delete the old one. Just in case something goes wrong, you still have the original service.
a month ago
Tried both suggestions:
Added --link to COPY --from commands - Build succeeded, but the deployed service returned 500 errors for all static assets (/assets/.js, /assets/.css). The page was blank. Had to delete the new service.
Added # syntax=docker/dockerfile:1.4 as first line - Same result as above.
Reverted to original service. The COPY --from=fe cache issue persists.
The --link flag seems to break asset serving on Railway's builder. Any other ideas for forcing cache invalidation on COPY --from layers?
a month ago
Thank you! The marker file diagnostic worked perfectly.
Results:
Added RUN printf '%s\n' 'recovery-check-2026-10-11-a' > /app/frontend/dist/build-revision.txt after npm run build
Deployed with NO_CACHE=1 (build logs show "Caching Disabled", all COPY --from steps ran without cache)
Fetched https://www.k-humor.com/build-revision.txt → returns recovery-check-2026-10-11-a with HTTP 200
This proves the new build IS live. The Docker cache was working correctly - it reuses layers when files are unchanged, which is expected behavior. My earlier assumption about stale cache was wrong.
The real issue is in my application code (React event handling), not the infrastructure. Your diagnostic approach saved me from chasing the wrong problem.
Accepting this answer. Thanks again!