One mental model
A Dockerfile is a recipe for your app image. It starts from a base image, adds your app files, installs dependencies, documents the port, and sets the start command.
What goes inside
Docker reads the Dockerfile from top to bottom. Each line should make the app closer to being runnable on another laptop.
For a beginner web app, keep it boring. Pick the runtime image, set a working folder, copy files, install packages, and set the command that starts the server.
Node app example
Use this shape for a basic Node app. Change the start file or command to match your project.
The first line asks Docker BuildKit to use the current stable Dockerfile syntax. The FROM line must come before normal build instructions.
# syntax=docker/dockerfile:1
FROM node:22-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
EXPOSE 3000
CMD ["node", "./src/index.js"]Read each line
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 6 done
EXPOSE is not publish
EXPOSE does not make your app visible on your laptop by itself. It only documents the container port.
Port publishing happens later when you run the container, and in this track you will handle it properly with Compose. Do not treat EXPOSE as a magic network switch.
Ask AI carefully
You can ask ChatGPT, Gemini, or Claude to draft a Dockerfile for your exact stack. Paste your package file, start command, app port, and folder structure.
Check what it returns. The Dockerfile should start with FROM, install dependencies, copy the app, include the real port, and use your actual start command. Do not accept random ports or commands.
Prompt:
Create a beginner Dockerfile for this web app.
Stack: Node.js
Package manager: yarn
Start command: node ./src/index.js
App listens on port: 3000
Files: package.json, yarn.lock, src/index.js
Keep it simple for local hackathon review.Do not hide secrets
Do not put database passwords, API keys, or UPI/payment keys in the Dockerfile with ENV. ENV values stay in the image metadata and can be inspected later.
For now, leave secrets out. A later lesson will show how to handle environment variables safely with Compose and an example env file.
Do this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done