Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Why is it highly recommended to use the `node:20-alpine` base image instead of the standard `node:20` image when writing a production Dockerfile?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Create Dockerfile for Node.js pipeline. Include the setup and basic execution steps.
You are reviewing a Create Dockerfile for Node.js pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Copying the entire project before running npm install, defeating layer caching
// Wrong: any file change re-triggers npm install
COPY . .
RUN npm install
// Correct: install layer only invalidates when dependencies change
COPY package*.json ./
RUN npm install
COPY . .The Solution //
Running `COPY . .` before `npm install` means Docker invalidates the install layer's cache on every single source code change, forcing a full dependency reinstall on every rebuild even though package.json didn't change. Copy only package*.json first, run npm install/ci, and copy the rest of the source afterward so unrelated code edits don't force a slow reinstall.
The Error //
Never adding a .dockerignore, so node_modules and .env get copied into the image
// .dockerignore
node_modules
.env
.git
npm-debug.logThe Solution //
Without a .dockerignore file, `COPY . .` copies your local node_modules (built for the wrong OS/architecture) and potentially a .env file full of secrets straight into the image, bloating it and risking credential leakage if the image is ever pushed to a registry. Add a .dockerignore excluding node_modules, .env, and .git before building.