Skip to content

15 min read

Multi-stage Docker build for Node.js

In one sentence: A small image carries only what your API needs to run: fewer megabytes to download and fewer programs an attacker can take advantage of. With a multi-stage Dockerfile, some stages install and check, and the final image copies only the result from them, with an unprivileged user and a health check.

What you will learn

  • Compare the slim, alpine, distroless and full base images by their size and by what they bring inside.
  • Write a multi-stage Dockerfile that checks the types at build time and leaves out the development dependencies.
  • Run the API with an unprivileged user and check it with whoami.
  • Add a HEALTHCHECK and read healthy and unhealthy in docker ps.

Before you start, read: 03-dockerfile.md

The shop’s image you built in lesson 3 works, but it carries everything. Inside are TypeScript and drizzle-kit, which are only for development; the cache npm left behind when installing, 34 MB; the tests and the scripts. That’s 145 MB that get downloaded every time a server needs it.

And its program runs as rootThe Linux administrator, user number 0. Permissions don’t apply to it and it can do anything, so it’s used as little as possible.Go to definition. If someone finds a flaw in the API and manages to run commands inside the container, they do it as the administrator: they can change the shop’s code or install whatever they want.

In this lesson you bring it down to 92 MB, with no development tools, no root and a health check.

The analogy

In a restaurant, the kitchen is full of things: knives, pots, peelings, the recipe book. The cook tastes the sauce before serving it. But the kitchen doesn’t reach the customer: the dish does, clean, with just what it needs.

A multi-stage Dockerfile does the same. The first stages are the kitchen: they install everything and check that the code is right. The last one is the dish: only what the API needs to work.

Where the analogy breaks down

  • The kitchen isn’t thrown away: the stages stay in your computer’s cache, for next time. What they don’t do is travel in the image.
  • The cook tastes the sauce without anyone asking. Docker only runs a stage if the final one copies something from it: if not, it skips it, as you’ll see.
  • The dish has no knives, but the final image does carry a minimal Linux with Node and npm: small, not empty.

What an image doesn’t need weighs and can be attacked

Section titled “What an image doesn’t need weighs and can be attacked”

Every file in an image costs twice:

  • In megabytes. Every server that starts your API downloads the image, and every deployment (Phase 8) waits for that download.
  • In risk. Every program inside is one more tool for whoever breaks in, and one more place where there can be a known security flaw. All of that is the attack surface: the fewer pieces, the smaller the surface.

Compare two Node 26 images, the full one and slim. dpkg -l lists the installed Debian packages, and grep -c ^ii counts them:

How many packages does each one bring?

Ventana de terminal
docker run --rm node:26 sh -c 'dpkg -l | grep -c ^ii'
docker run --rm node:26-slim sh -c 'dpkg -l | grep -c ^ii'

What you will see:

453
80

node:26 brings 453 packages, among them gcc (a compiler), git, python3 and curl: they’re there to compile almost anything inside. node:26-slim brings 80, and none of those four. Your API uses none of them.

node:26 downloads 452 MB: if you’d rather not, look at our output. Your numbers may vary.

The same goes for npm. When it installs, it checks the packages against a list of known flaws: with the development dependencies, it warns of 4 moderate vulnerabilities; with only the production ones, of none. You’ll see it in “Try it.”

The Base imageThe image another one starts from, the one in the FROM of its Dockerfile, like node:26-slim. It provides the system and the programs that sit under your layers, so a good part of your image’s size and of its known security flaws depends on it.Go to definition is the one in FROM: it provides the system underneath your layers, and with it, most of the size. For Node there are four common ones:

The four, side by side

Ventana de terminal
docker image ls --filter 'reference=node:26*' --filter 'reference=gcr.io/distroless/nodejs26*'

What you will see:

IMAGE ID DISK USAGE CONTENT SIZE EXTRA
gcr.io/distroless/nodejs26-debian13:latest c85d869757a6 253MB 60.2MB
node:26 32fa97f33639 1.8GB 452MB
node:26-alpine 143494b1da29 258MB 68.2MB
node:26-slim 193fe51b64e7 378MB 88.4MB

--filter reference=… keeps the images whose name matches any of the filters. To see them, you first have to download them with docker pull: about 670 MB for the four. Look at CONTENT SIZE, what gets downloaded. Your sizes and IDs will be different.

Base image What it brings Download
node:26 Full Debian, with tools to compile 452 MB
node:26-slim Minimal Debian and Node 88 MB
node:26-alpine Alpine, another minimal Linux, and Node 68 MB
nodejs26-debian13 (distroless, from Google) Node and the libraries it needs; no shell, no apt 60 MB

The two smallest ones come with fine print.

Almost every Linux program relies on a C library: the shared code to open files, reserve memory or use the network. Debian uses glibc; Alpine, a smaller one, musl. docker run --rm node:26-alpine ldd --version confirms it: musl libc.

For your API it makes no difference: it’s JavaScript. But some npm packages bring native code, almost always compiled for glibc. On musl they may have no version, try to compile themselves when installing (the course’s .npmrc doesn’t let those scripts run) or fail in strange ways. The shop uses none; your next project might.

Distroless images (“without a distribution”) only carry the program and what it needs. Node works; a ShellThe program that reads what you type in the terminal, interprets it and runs it. The most used are bash, the one on almost every Linux, and zsh, the one on macOS.Go to definition doesn’t:

An image without a shell

Ventana de terminal
docker run --rm gcr.io/distroless/nodejs26-debian13 -e "console.log(process.version)"
docker run --rm --entrypoint sh gcr.io/distroless/nodejs26-debian13

What you will see:

v26.11.0
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "sh": executable file not found in $PATH
Run 'docker run --help' for more information
  • The first one works: this image starts node, and -e passes it code.
  • --entrypoint sh changes the program the container starts to sh, which doesn’t exist.

Whoever breaks in has no shell. Neither do you: you can’t get in with docker exec -it … sh to look around.

The course uses node:26-slim: almost as small, with glibc, and with a shell to look inside. With alpine, the shop would come down to a 74 MB download, and with distroless, to 66 MB, against 92 MB.

This is the shop’s new Dockerfile. It has three FROMs, and each one starts a stage:

Dockerfile
# The image of the shop's API, small and safe (Phase 7, lesson 4). Build it with:
# docker build -t shop-api .
#
# Three stages, each from its own FROM: the first two install and check, and only the last one
# becomes the image. What the first ones need (TypeScript, npm's cache, the tests) stays in them.
#
# Sizes, measured on 2026-10-14 with docker image ls (CONTENT SIZE: what's downloaded, compressed;
# in parentheses, what it takes up uncompressed, the sum of docker history):
# the image from lesson 3, with a single stage: 145 MB (451 MB)
# this one, on node:26-slim: 92 MB (343 MB)
# the same final stage on node:26-alpine: 74 MB (243 MB)
# and on distroless (gcr.io/distroless/nodejs26-debian13): 66 MB (244 MB)
# slim, and not alpine or distroless: alpine uses another C library (musl) that some package with
# native code fails with, and distroless doesn't even bring a shell to look inside the container.
# Stage 1, dependencies: all of them, the development ones too (TypeScript, to check the types).
# node:26-slim, pinned by its digest.
FROM node:26-slim@sha256:193fe51b64e77981119c98c2002c9e32a70e2f006fb4d25068ce0558998917f0 AS dependencies
WORKDIR /app
# .npmrc too: without it, npm ci would run the packages' install scripts.
COPY package.json package-lock.json .npmrc ./
RUN npm ci
# Stage 2, check: starts from the previous one, copies the code and checks the types. If a type
# fails, the image isn't built. The tests don't run here: they need PostgreSQL.
FROM dependencies AS check
COPY . .
RUN npm run check
# Stage 3, the final image: from node:26-slim again, clean, with only what's needed to run the
# API.
FROM node:26-slim@sha256:193fe51b64e77981119c98c2002c9e32a70e2f006fb4d25068ce0558998917f0 AS final
WORKDIR /app
COPY package.json package-lock.json .npmrc ./
# Only the production dependencies (--omit=dev: without TypeScript or drizzle-kit), and without the
# cache npm leaves behind when installing.
RUN npm ci --omit=dev && npm cache clean --force
# The code, from the check stage, not from the project: BuildKit skips the stages the final one
# takes nothing from, and then the types would never be checked.
COPY --from=check /app/src ./src
ENV NODE_ENV=production HOST=0.0.0.0
# Not as root: node is an unprivileged user that comes with the image. If someone breaks into the
# API, they can't change its code (it belongs to root) or install anything.
USER node
EXPOSE 3000
# Every 10 seconds, Docker asks /health whether the shop is fine, and docker ps shows it: healthy
# or unhealthy. The image doesn't bring curl, so it asks with Node's fetch.
HEALTHCHECK --interval=10s --timeout=3s CMD ["node", "-e", "fetch('http://127.0.0.1:3000/health').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]
CMD ["node", "src/server.ts"]

It’s a Multi-stage buildA Dockerfile with several stages, each one starting from its own FROM. The first ones install, compile or check, and the last one copies from them only what the program needs to run. Everything else, like the development tools, stays out of the final image.Go to definition: several stages, and only the last one becomes the image. Word by word:

  • FROM … AS dependencies: AS gives the stage a name. This is the one from lesson 3: it installs all the dependencies, the development ones too (devDependencies, from Phase 3).
  • FROM dependencies AS check: a stage can start from another one. This one copies the project and runs npm run check, the tsc --noEmit from Phase 3, which goes over the whole project, tests included. If a type is wrong, tsc ends with an error and the build stops: there’s no image.
  • FROM node:26-slim… AS final: starts again from scratch, from the base image. Nothing from the earlier stages gets here unless you copy it.
  • npm ci --omit=dev: installs only the production dependencies. && npm cache clean --force deletes npm’s cache in the same RUN: deleted in another step, it would still take up space in its Layer (of an image)Each of the read-only pieces that make up a Docker image. It holds the files that one step of the image’s recipe added, changed or deleted, and the layers stack up to form the container’s files. It’s named by the fingerprint of its content, so several images share the layers that are identical and they’re stored only once.Go to definition, as you saw in lesson 2. npm asks for --force as a precaution, and that’s why it warns.
  • COPY --from=check /app/src ./src: copies the src folder from the check stage, not from your computer. You’ll see why in a moment.
  • ENV NODE_ENV=production: this way many Node libraries know they’re in production.

USER and HEALTHCHECK have their own sections. The final image keeps package.json, its lockfile, .npmrc, the production dependencies and src/: no tests, no scripts, no TypeScript.

BuildKit, Docker’s builder, only builds the stages the final one needs. If the last one copies nothing from check, it doesn’t run it.

We tested it with a deliberate mistake: in src/app.ts, pool.querry instead of pool.query, and the last COPY line changed to COPY src ./src, which copies from your computer. This is the build log, trimmed:

#5 [final 1/5] FROM docker.io/library/node:26-slim@sha256:193fe51b…
#6 [final 2/5] WORKDIR /app
#6 CACHED
#7 [final 3/5] COPY package.json package-lock.json .npmrc ./
#7 CACHED
#8 [final 4/5] RUN npm ci --omit=dev && npm cache clean --force
#8 CACHED
#9 [final 5/5] COPY src ./src
#9 DONE 0.0s
#10 naming to docker.io/library/shop-api:latest done

The build finishes fine, with the mistake inside, and with no trace of check or dependencies. With COPY --from=check, the final stage depends on that stage, and Docker has to build it: the types are always checked. (We captured it with another image name, changed to shop-api.)

Inside a container, the program is root unless you say otherwise. In lesson 1 you saw it with whoami in nginx.

It looks harmless, but it’s user 0 of the kernel all containers share. Docker takes away some of its powers, and even so:

  • Inside, it can change the API’s code, install programs with apt or read any file.
  • Outside, if a flaw shows up in Docker or in the kernel that lets it escape the container, it escapes as the machine’s root.

It’s the Least privilegeThe rule of giving each user and each program only the permissions it needs, and no more. If something fails or someone gets in where they shouldn’t, the damage stays within the little it could touch.Go to definition from the users lesson of Phase 1: the API only needs to read its code and open port 3000. USER node makes what comes after it, and the container when it starts, run as node, an unprivileged User (in Linux)An identity on the system, with a name and a number. Each person has their own, and each program on a server usually has another of its own. Every file has a user as its owner, and every process runs on behalf of one.Go to definition that comes with the base image. The code was copied by root: node can read it, but not change it.

USER node goes at the end, after installing: npm ci needs to write in /app, which belongs to root.

docker ps says Up as long as the process is alive, but the API can be running and not serving: without PostgreSQL, almost all its routes fail. For that, the new route, GET /health:

src/app.ts
// Is the shop fine? The Dockerfile's HEALTHCHECK asks every few seconds (in Phase 8, the load
// balancer too). Without the database the shop can hardly do anything, so it only answers 200 if
// PostgreSQL replies; if not, 503 Service Unavailable.
app.get('/health', async (c) => {
try {
await pool.query('SELECT 1');
return c.json({ status: 'ok' });
} catch {
return httpProblem(c, 503, 'The database is not responding');
}
});

It runs the smallest query, SELECT 1. If PostgreSQL replies, 200 and {"status":"ok"}; if not, 503 Service Unavailable, with the error format from Phase 4. To use pool, src/app.ts also gains a line at the top: import { pool } from './db.ts';.

The HEALTHCHECK instruction tells Docker how to ask. It’s a HealthcheckA command Docker runs every few seconds inside a container to find out whether its program really works, not just whether it’s running. If it ends well, the container is healthy; after several failures in a row, it’s unhealthy. Compose uses it to wait for a service before starting the ones that depend on it.Go to definition:

  • --interval=10s: it asks every 10 seconds. --timeout=3s: if it takes more than 3, it counts as a failure.
  • CMD [...]: the command it runs inside the container. If its Exit codeThe number a program leaves when it finishes. 0 means it went well, and any other, from 1 to 255, that something failed. The shell keeps it in $?, and scripts check it to decide whether to go on.Go to definition is 0, all good; if it’s 1, not good. The image doesn’t bring curl, so it asks with Node’s fetch: r.ok is true with a 200.
  • After three failures in a row (the default value), Docker marks the container unhealthy.

Docker only notes it down: it doesn’t restart an unhealthy container. Others use it: Compose, in lesson 7, and in Phase 8 the deployment script, which waits for the new API to be healthy. nginx, in front, doesn’t look at it: it sets a copy aside when a real request fails, as you’ll see in Phase 8’s reverse proxy lesson.

An image gets shared: you push it to a Image registryA service that stores Docker images so they can be downloaded with docker pull and published with docker push. The best known is Docker Hub, the one Docker uses unless you tell it another.Go to definition (lesson 8) or you hand it to Luis. Whoever has the image can read every file in every layer, even if a layer above deletes it. If your .env gets in, your secrets get in.

That’s why lesson 3’s .dockerignore leaves out .env and node_modules: docker build doesn’t send them, and COPY . . doesn’t find them. The final stage adds another barrier: it only copies src/.

The goal: bring your shop’s image down to two thirds of its size, and prove that it doesn’t run as root, that it doesn’t carry your .env and that Docker knows whether it’s fine.

The outputs are from Docker Engine 29 on a Mac, captured with other names and another port, which we’ve changed to the lesson’s. Your IDs, fingerprints, sizes and times will be different.

You’re working in ~/backend-course/phase-3/shop-api, with the shop-api image from lesson 3. Give it another name, to compare it later:

Ventana de terminal
cd ~/backend-course/phase-3/shop-api
docker image tag shop-api shop-api:single-stage

docker image tag adds a Tag (of an image)The version name that goes after the colon in a Docker image’s name, like 26-slim in node:26-slim. If you don’t write one, Docker uses latest. Anyone who can write to the registry can move a tag to another image whenever they want, so it doesn’t guarantee which image you get.Go to definition to an image that already exists, without copying it. If it goes well, it doesn’t print anything.

Download this lesson’s step and copy the three files that change: the Dockerfile, src/app.ts, with /health, and the new test, which checks both:

Ventana de terminal
cd ~/backend-course/phase-3
curl -O https://backenddesdecero.com/practicas/shop-api/33-small-image.tar.gz
tar -xzf 33-small-image.tar.gz
cd shop-api
cp ../33-small-image/Dockerfile .
cp ../33-small-image/src/app.ts src/
cp ../33-small-image/test/docker.test.ts test/

1. The image in three stages

Ventana de terminal
docker build --progress=plain -t shop-api .

What you will see:

…
#4 [dependencies 1/4] FROM docker.io/library/node:26-slim@sha256:193fe51b64e77981119c98c2002c9e32a70e2f006fb4d25068ce0558998917f0
…
#7 [dependencies 3/4] COPY package.json package-lock.json .npmrc ./
#7 DONE 0.0s
#8 [final 4/5] RUN npm ci --omit=dev && npm cache clean --force
#8 3.707 added 53 packages, and audited 54 packages in 3s
…
#8 3.708 found 0 vulnerabilities
#8 3.811 npm warn using --force Recommended protections disabled.
#8 DONE 4.1s
#9 [dependencies 4/4] RUN npm ci
…
#9 4.760 added 74 packages, and audited 75 packages in 4s
…
#9 4.768 4 moderate severity vulnerabilities
…
#9 DONE 4.8s
#10 [check 1/2] COPY . .
#10 DONE 0.1s
#11 [check 2/2] RUN npm run check
#11 0.175
#11 0.175 > shop-api@1.0.0 check
#11 0.175 > tsc --noEmit
#11 0.175
#11 DONE 0.7s
#12 [final 5/5] COPY --from=check /app/src ./src
#12 DONE 0.1s
#13 exporting to image
…
#13 naming to docker.io/library/shop-api:latest done
…

Each step carries the name of its stage. Look at three things:

  • [check 2/2] RUN npm run check runs, and tsc says nothing: the types are right.
  • The steps overlap: [final 4/5] starts before [dependencies 4/4]. Stages that don’t depend on each other are built at the same time.
  • The vulnerabilities: 53 production packages and no known ones; 74 with the development ones, and 4.

The first three steps are the same in dependencies and in final, and Docker does them once. The dependencies ones are lesson 3’s: you’ll get them CACHED, without npm ci’s output. We’ve removed (…) lines from npm and from Docker.

2. Before and after

Ventana de terminal
docker image ls shop-api

What you will see:

IMAGE ID DISK USAGE CONTENT SIZE EXTRA
shop-api:latest 65f95ba136c8 435MB 92.1MB
shop-api:single-stage de88a8019cbc 596MB 145MB

From 145 MB to 92 MB of download, 37% less: mostly TypeScript and company, about 69 MB on disk, and the 34 MB of npm’s cache. We’ve adjusted the space between columns.

3. root before, node now

Ventana de terminal
docker run --rm shop-api:single-stage whoami
docker run --rm shop-api whoami

What you will see:

root
node

whoami replaces the image’s CMD, like ls -a in lesson 3: you’re root in the old one, and node in the new one.

4. What’s inside, and who owns it

Ventana de terminal
docker run --rm shop-api ls -la
docker run --rm shop-api touch src/hello.ts

What you will see:

total 112
drwxr-xr-x 1 root root 4096 Oct 14 05:25 .
drwxr-xr-x 1 root root 4096 Oct 14 05:25 ..
-rw-r--r-- 1 root root 226 Oct 14 05:25 .npmrc
drwxr-xr-x 48 root root 4096 Oct 14 05:25 node_modules
-rw-r--r-- 1 root root 86038 Oct 14 05:25 package-lock.json
-rw-r--r-- 1 root root 1458 Oct 14 05:25 package.json
drwxr-xr-x 3 root root 4096 Oct 14 05:25 src
touch: cannot touch 'src/hello.ts': Permission denied

ls -la lists /app, the working folder. There’s no .env, no test/ and no scripts/. Everything belongs to root, with the permissions from Phase 1: rw-r--r-- on the files and rwxr-xr-x on the folders. Everyone else, like node, doesn’t have the w: they read, but don’t write. That’s why touch, which tries to create a file in src, answers Permission denied.

If you see a .env, check your .dockerignore.

Start the container with the command from lesson 3, the one for your system, and look at docker ps:

5. Start it and look at its health

Ventana de terminal
docker run -d --name shop -p 127.0.0.1:3000:3000 --env-file .env \
-e DATABASE_URL=postgres://shop:shop@host.docker.internal:5432/shop shop-api
docker ps

What you will see:

b9752f8acba5eaaabf861a95e673ddb37b4dcb44ce7c9bb613be9a40afe10f04
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9752f8acba5 shop-api "docker-entrypoint.s…" 4 seconds ago Up 4 seconds (health: starting) 127.0.0.1:3000->3000/tcp shop

STATUS says (health: starting): Docker hasn’t asked yet.

Wait a few seconds and run docker ps again:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9752f8acba5 shop-api "docker-entrypoint.s…" 15 seconds ago Up 15 seconds (healthy) 127.0.0.1:3000->3000/tcp shop

(healthy): /health answered 200. docker logs shop shows a request to /health every 10 seconds: those are Docker’s.

If the container doesn’t show up, look at docker logs shop: the missing configuration appears there. If on Windows you couldn’t reach your PostgreSQL in lesson 3, here you’ll see (unhealthy): lesson 6 solves it. Our PostgreSQL was in another container, as in lesson 6; the states are the same.

Now stop PostgreSQL: on the Mac, brew services stop postgresql@18; on Ubuntu and WSL, sudo pg_ctlcluster 18 main stop. Wait half a minute:

6. Without a database

Ventana de terminal
docker ps

What you will see:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9752f8acba5 shop-api "docker-entrypoint.s…" 41 seconds ago Up 41 seconds (unhealthy) 127.0.0.1:3000->3000/tcp shop

(unhealthy), after three failed questions, one every 10 seconds. It’s still Up: Docker doesn’t restart it. curl -i http://localhost:3000/health answers 503 Service Unavailable.

Start it again (start instead of stop) and, a few seconds later, docker ps says (healthy) again.

Challenge: in src/app.ts, write pool.querry instead of pool.query and build the image again. What happens to your shop-api image?Show answer

The build stops at check:

#10 [check 2/2] RUN npm run check
#10 1.180 src/app.ts(99,16): error TS2551: Property 'querry' does not exist on type 'Pool'. Did you mean 'query'?
#10 ERROR: process "/bin/sh -c npm run check" did not complete successfully: exit code: 1
…
ERROR: failed to build: failed to solve: process "/bin/sh -c npm run check" did not complete successfully: exit code: 1

tsc ends with code 1 and Docker doesn’t create the image: shop-api is still the good one. Without check, it would have been built, and /health would always answer 503. Put pool.query back as it was.

To finish, delete the container and the old image:

7. Clean up

Ventana de terminal
docker rm -f shop
docker image rm shop-api:single-stage

What you will see:

shop
Untagged: shop-api:single-stage
Deleted: sha256:de88a8019cbc13dc3b56f2f211ecfe9cdadaf5b807f8e2dcde66ec672def0a79

docker rm -f stops and deletes the container at once. The shop-api image stays: you’ll use it in the following lessons.

  • devDependencies. In Phase 3, --save-dev set apart what’s only for development. --omit=dev uses that list.
  • www-data and postgres. In Phase 1, each server had its own user. USER node is the same thing.
  • The missing ps. In lesson 1, docker exec web ps didn’t find ps: images already come trimmed down.
  • Deleting in another RUN. RUN npm cache clean --force on its own line saves nothing: the cache is still in npm ci’s layer.
  • Copying node_modules from the install stage. COPY --from=dependencies /app/node_modules brings the development ones along too.
  • USER node too early. Right after WORKDIR /app, npm ci runs as node and can’t write in /app, which belongs to root: EACCES: permission denied, mkdir '/app/node_modules'.
  • A HEALTHCHECK with curl in an image without curl. The command always fails, and the container comes out unhealthy even though the API works fine.
  • What an image doesn’t need costs in download and in attack surface: fewer programs, fewer known flaws and fewer tools for an attacker.
  • slim is the course’s base: minimal Debian, with glibc and a shell. Alpine uses musl, which can break native packages; distroless has no shell.
  • In a multi-stage Dockerfile, only the last stage is the image. The others install and check, and the final one copies what it needs from them; if it copies nothing from one, BuildKit skips it.
  • npm ci --omit=dev && npm cache clean --force, in the same RUN, leaves only the production dependencies.
  • USER node runs the API without privileges, and HEALTHCHECK makes docker ps say healthy or unhealthy depending on /health.
Luis wants to add RUN rm -rf /root/.npm on a new line, at the end of the single-stage Dockerfile, so the image weighs less. Does he manage it?

Ana changes COPY --from=check /app/src ./src to COPY src ./src, because “it’s the same.” The next day she pushes a type error and the image builds without complaining. Why?

Your API uses an npm package that brings compiled native code. You change FROM node:26-slim to node:26-alpine to save 20 MB, and the image no longer starts. What’s the most likely cause?

Your container shows (unhealthy) in docker ps, but curl to /v2/products answers fine from your computer. What do you look at first?

Someone manages to run commands inside your container, which has USER node. What can they do?

Luis removes .env from your .dockerignore “because the final image only copies src/.” Is your .env safe?

phase-7 · lesson 4/8