Multistage Dockerfile Builder
Generates a multistage Dockerfile (builder + runtime) for Node.js apps — copies node_modules only from the builder.
—
Why a multi-stage build keeps the image small
A carelessly built Docker image carries everything used to build it: compiler, development dependencies, package manager cache, source code. That bloats the image, lengthens deployment and widens the attack surface — every extra tool in there is another tool in the hands of anyone who gets inside the container.
A multi-stage build cuts that off at the root. A first stage, the builder, installs everything and compiles. A second stage starts from a clean image and copies only the result, with COPY --from=builder. Everything left behind in the first stage is discarded and never reaches the final image. Enter the Node version and the page generates the Dockerfile with both stages already wired up.
The order of instructions in the generated file is not accidental. package.json is copied and dependencies installed before the rest of the code, because each instruction becomes a layer with its own cache: changing one line of source does not invalidate the npm ci layer, and the next build reuses what was already there. Swapping those two lines makes the whole install run again on every change.
Frequently asked questions
How many stages can I have?
Why npm ci rather than npm install?
Does the final image have to match the builder?
Related Tools
Dockerfile Generator
Build a Dockerfile from common templates: Node, Python, Go, Static Nginx, with optional multi-stage, healthcheck and non-root user. Everything in your browser.
Docker Run → Compose
Convert a docker run command to the equivalent docker-compose.yml automatically. Maps ports, volumes, environment variables, networks and restart policies.
docker-compose PostgreSQL Generator
Generate a ready-to-use docker-compose for PostgreSQL, with user, password, database and a persistent volume set up. Spin up your local DB with one command.
docker-compose MongoDB Generator
Generates a ready-to-use docker-compose for MongoDB, with root user and password, port 27017 published and a persistent volume. You create the database after it starts.
docker-compose Elasticsearch Generator
Generate a ready-to-use docker-compose for single-node Elasticsearch, with memory and volume configured. Spin up your local search engine with one command.
VS Code tasks.json Generator
Build a VS Code tasks.json with label, type, command, group and problemMatcher. Includes configurable default shell.