🐳 Docker Learning Hub
Lesson 3 • Build your first real Dockerized app
Lesson 3

Build your first real Dockerized app

This page uses a small Node.js app so you can see the full Docker workflow clearly: create files, write a Dockerfile, build an image, run a container, and test it.

Goal

Package a tiny web app so it runs the same way anywhere Docker is installed.

Result

You will understand the full end-to-end flow, not just separate commands.

What changes now

You move from theory into a practical example with realistic files and commands.

Step-by-step flow

1. Write app filesCreate a tiny Node.js server and package file.
2. Write DockerfileTell Docker how to package the app.
3. Build imageTurn the project into a reusable image.
4. Run containerStart the app and test it in the browser.

Project files

server.js
The app code that returns a simple response.
package.json
The Node.js metadata and start command.
Dockerfile
The instructions Docker uses to build the image.

Example `server.js`

const http = require("http"); const server = http.createServer((req, res) => { res.writeHead(200, { "Content-Type": "text/plain" }); res.end("Hello from Docker Lesson 3"); }); server.listen(3000, () => { console.log("Server running on port 3000"); });

Example `package.json`

{ "name": "docker-lesson-3-app", "version": "1.0.0", "main": "server.js", "scripts": { "start": "node server.js" } }

Dockerfile for this app

FROM node:18 WORKDIR /app COPY package.json /app COPY server.js /app EXPOSE 3000 CMD ["npm", "start"]
This uses Node 18 as the base image, copies the app files into the container, exposes port 3000, and starts the app with `npm start`.

Why this Dockerfile is beginner-friendly

  • It is short enough to understand line by line.
  • It shows `FROM`, `WORKDIR`, `COPY`, `EXPOSE`, and `CMD` in one place.
  • It connects directly to what you learned in Lesson 2.

Build and run commands

docker build -t lesson-3-app . docker run -d -p 3000:3000 lesson-3-app docker ps

After this, you can open http://localhost:3000 in your browser.

How to verify it worked

  • Check that `docker ps` shows your running container.
  • Open the browser and confirm the app response appears.
  • Use `docker logs <container_id>` if something does not work.
  • Use `docker stop <container_id>` when you want to stop it.

What you learned in Lesson 3

App files matter first
Docker packages a real app, not just commands.
Dockerfile connects code to image
It turns your project into a reusable package.
Image becomes container
The container is the running version of the packaged app.
Testing closes the loop
You should always verify the app actually runs after `docker run`.

Next page: Lesson 4 explains how Docker keeps important data safe using volumes.