Software DevelopmentBeginner 1 to 2 hours

Optimize a Node.js Dockerfile

Shrink a bloated 1GB Docker image down to under 150MB.

The Scenario

A junior developer wrote a `Dockerfile` for a simple Node.js Express API. The resulting image is 1.2GB because they used the `node:latest` base image, copied the `node_modules` folder from their local machine, and ran as the `root` user.

The Brief

Rewrite the Dockerfile. Use a smaller base image (e.g., Alpine), utilize multi-stage builds to exclude development dependencies (`devDependencies`), and ensure the container runs as a non-root user for security.

Deliverables

  • The optimized `Dockerfile`
  • An explanation of why multi-stage builds are critical for compiled languages (or for trimming `devDependencies` in Node)

Submission Guidance

A good Dockerfile should cache the `package.json` install step separately from the source code copy step to speed up rebuilds.

Submit Your Work

Your submission is graded against the rubric on the right. If you pass, you get a public Badge URL you can share on LinkedIn. There is no draft save, so work offline first and paste your finished response here.

This appears on your public Badge.

0/20000 charactersMarkdown supported

One per line or comma separated. Up to 5 links.

By submitting, you agree your submission text, name, and evaluation will appear on a public Badge URL.