Container Compendium
Here is your high-density field manual for the core Docker terminology and Node.js containerization workflow we covered in this lesson.
Syntax Chart
Section titled “Syntax Chart”| Syntax | Purpose | Example |
|---|---|---|
FROM | Defines the base image foundation | FROM node:20-alpine |
WORKDIR | Sets the internal execution directory | WORKDIR /app |
COPY | Copies files from the host to the image | COPY package*.json ./ |
RUN | Executes a command during the build | RUN npm install |
EXPOSE | Documents the expected internal port | EXPOSE 3000 |
CMD | Defines the default runtime command | CMD ["npm", "start"] |
docker build | Constructs the image from the recipe | docker build -t app-name . |
docker run | Starts a container from an image | docker run -p 8080:3000 app-name |
-p flag | Maps host port to container port | -p 8080:3000 |
The Cargo Manifest
Section titled “The Cargo Manifest”The required baseline pieces to package a standard Node.js application:
- Dockerfile: The exact recipe used at the root of the project to build the image.
- .dockerignore: Prevents local files (especially
node_modulesand.env) from bleeding into the image. - package.json: Must include a valid
startscript for theCMDinstruction to trigger. - Docker Engine: Must be running locally on your machine to build or execute containers.
The Hazard Map
Section titled “The Hazard Map”| Problem | Likely Cause | Quick Fix |
|---|---|---|
| Build is incredibly slow | Incorrect instruction order invalidating cache | Move COPY package*.json ./ and RUN npm install before COPY . . |
| Strange Node module errors | Host node_modules were copied into the Linux image | Add node_modules to your .dockerignore file |
| Container exits instantly | The default CMD process failed or finished immediately | Check package.json for a missing or crashing start script |
| ”Cannot connect” in browser | Traffic isn’t crossing from the host into the container | Verify you used -p hostPort:containerPort (e.g. -p 3000:3000) |
| Build fails immediately | Docker can’t find the build context | Ensure you included the trailing . in the docker build -t name . command |
Solo’s Pro-Notes
Section titled “Solo’s Pro-Notes”- Images vs Containers: You build static images. You run live containers. An image is the class; a container is the object.
- Documentation only:
EXPOSEdoes absolutely nothing operational by itself. It’s a sticky note for other developers. You must manually map the ports when running. - Cache invalidation: A change to line X in a Dockerfile invalidates the cache for line X and every single line below it.
- Local Dev vs Containers: Don’t rely on your laptop’s invisible configuration. Push your requirements into the
Dockerfileso the app is self-sufficient.
Pack it Right
Consistency is the goal. When you ship the environment alongside the code, you strip away an entire category of stressful deployment errors.
Immutability Rule
If you ever find yourself “logging into” a running container to manually fix a
configuration file, you have failed the test. Fix the Dockerfile and rebuild
the image.
Extra Bits & Bytes
Section titled “Extra Bits & Bytes”Docker Fundamentals Study Guide
Complete Node Aboard Demo GitHub Repo