---
title: "Discussion on \"Multi-Stage Docker Builds for NestJS: What Nobody Tells You\" | Hashnode"
description: "Discussion on \"Multi-Stage Docker Builds for NestJS: What Nobody Tells You\". The gotchas that cost me hours — from nest-cli.json not being copied, to tsconfig CommonJS quirks, to build outputs not landing in the right dist folder."
url: "https://hashnode.com/posts/multi-stage-docker-builds-for-nestjs-what-nobody-tells-you/69e372c99020749e6a1bd912"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Multi-Stage Docker Builds for NestJS: What Nobody Tells You](https://iiamantoni.hashnode.dev/multi-stage-docker-builds-for-nestjs-what-nobody-tells-you?utm_source=hashnode&utm_medium=feed)

The gotchas that cost me hours — from nest-cli.json not being copied, to tsconfig CommonJS quirks, to build outputs not landing in the right dist folder.

Apr 18 · 6 min read · iiamantoni.hashnode.dev  
Read the article

-   [#nestjs](https://hashnode.com/tag/nestjs)
-   [#docker](https://hashnode.com/tag/docker)

## Written by

[Muonaka Anthony](https://hashnode.com/@iiamantoni)

@iiamantoni · Remote

  
[View profile](https://hashnode.com/@iiamantoni)

Software developer

Anthony is a fullstack software engineer with a primary focus on frontend development and experience building high-visibility, scalable, and accessible web applications.

## Responses 1

Markdown supported · ⌘↵ to post

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 5](https://hashnode.com/posts/multi-stage-docker-builds-for-nestjs-what-nobody-tells-you/69e372c99020749e6a1bd912/comment/6aec2018e62b831a8fd3b8cf)

A Nest multi-stage image stays reliable when the builder alone runs install plus nest build (and any prisma generate / native compile), then the runtime stage copies only dist, the pruned production node\_modules, and the lockfile-derived tree — never the compiler, never a leftover .npm cache. Match libc between stages (glibc vs musl) so bcrypt-style .node addons do not fail at ERR\_DLOPEN after a “green” build. Listen on a private interface or Compose network only, run as non-root, set NODE\_ENV=production, and fail the image build if a required native binding is missing for the runtime arch rather than discovering it on first boot behind a proxy.

After rebuild I exec into the runtime container and require the native module once, then hit a readiness route that boots Nest plus a trivial crypto or DB ping from an adjacent proxy container on the internal network, and finally the same path through published TLS. A short 502 with a healthy container almost always means wrong internal port, missing network membership, or the process still compiling on start — move generation into the builder and keep start as node dist/main. Log upstream status beside request time at the edge so a crash-looping Nest worker is not mistaken for TLS or vhost drift.
