The challenge lab gives you the status page source with no Dockerfile. This page collects what you need; the lab gives no walkthrough.
The parts and where they came from
| Requirement | Instruction or file | Lesson |
|---|---|---|
| Node.js 20 on Alpine | FROM with a pinned variant tag | 2 |
App in /app | WORKDIR | 3 |
| Dependencies installed in the image | COPY the manifest, then RUN npm install | 3, 4 |
| Code changes do not reinstall | Manifest before code | 8 |
| Secrets and local files stay out | .dockerignore | 9 |
| Port documented | EXPOSE | 6 |
Clean shutdown on docker stop | CMD in exec form | 5 |
| A name to run and roll back | docker build -t NAME:VERSION . | 7 |
The shape of a Node.js Dockerfile
text
FROM base image, pinned
WORKDIR where the app lives
COPY dependency manifest only
RUN install dependencies
COPY the rest of the code
EXPOSE the app's port
CMD start command, exec formCheck your work
| Check | Command |
|---|---|
| Base OS and Node.js version | docker run --rm IMAGE cat /etc/os-release, docker run --rm IMAGE node --version |
| Working directory and files | docker run --rm IMAGE ls -a /app |
| No secret in the image | docker run --rm IMAGE cat /app/.env should fail |
| Cache order | Edit server.js, rebuild, look for CACHED on RUN npm install |
| Exposed port and command | docker image inspect IMAGE --format '{{json .Config.ExposedPorts}} {{json .Config.Cmd}}' |
| It runs | docker run -d --name NAME -p 8080:3000 IMAGE, then curl localhost:8080/health |
A healthy status page answers:
text
learner@pier:~/status-page$ curl localhost:8080/health
{"status":"ok","version":"1.0.0"}If the container exits, docker logs NAME shows Node.js's error: a missing module points at npm install, a missing /app/server.js at COPY or WORKDIR.