Computer Sciencebeginner6h guided build

Docker: Containerize and Ship Real Apps

Go from zero Docker knowledge to confidently containerizing a Node.js web app. You'll understand what containers are, write Dockerfiles, use Docker Compose, and ship an app that runs the same everywhere.

Build it yourself, get guided when you are stuck, and leave with proof you can actually show.

DockerNode.jsExpress

What you learn by building this

  • Understand what containers are and why they exist
  • Run and interact with Docker containers
  • Write a Dockerfile to containerize a Node.js app
  • Use Docker Compose to wire up multiple containers
  • Configure apps with environment variables inside Docker
  • Build and tag images for deployment

Challenge

Think first, then write

Before we explain anything — try this

Open your terminal and run this command exactly as written:

docker run hello-world

You should see a wall of text appear. Read it. Don't skim.

Then answer these two questions in your head before moving on:

  1. Where did this "hello-world" thing come from? You never downloaded a file.
  2. What is the difference between the first time you run this and the second time you run it?

Run it a second time now:

docker run hello-world

Notice anything different in the output?


If you got an error like docker: command not found, Docker isn't installed yet. Run the setup command for your system:

Mac: Install Docker Desktop from docker.com/products/docker-desktop — it's one .dmg file.

Linux (Ubuntu/Debian):

curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER

Then log out and back in, and re-run docker run hello-world.

Once you see the hello-world output, come back and keep reading.

What just happened

You ran a program without installing it. Think about that for a second.

No npm install. No brew install. No "make sure you have the right version of Node." You typed one command and something ran. That's the whole pitch of Docker.

Here's what actually happened in those few seconds:

Step 1: Docker looked for hello-world on your machine. It didn't find it.

Step 2: Docker pulled it from Docker Hub — a public registry of pre-packaged programs. This is the Unable to find image locally line you saw the first time.

Step 3: Docker ran it in a container — an isolated environment where the program can do its thing without touching anything else on your computer.

Step 4: The container exited. The program finished, and the container stopped.

The second time you ran it, there was no download. Docker had already stored the image locally. That's why it was instant.


Two terms you'll use constantly — get these clear now:

Image — the packaged blueprint. Think of it like a ZIP file of a complete environment: the OS, the dependencies, the code. The hello-world image lives on Docker Hub.

Container — a running instance of an image. When you run docker run hello-world, Docker unpacks the image and starts a container from it. The container runs, then exits.

One image can spawn dozens of containers. A container is always created from an image.

A useful analogy: if an image is a recipe, a container is a dish made from that recipe. You can cook the same recipe multiple times and get multiple dishes. The recipe doesn't change.


That line in the hello-world output — "This message shows that your installation appears to be working correctly" — is Docker confirming the entire pipeline works: your Docker client talked to the Docker daemon, the daemon pulled from the registry, and it executed in a container. All of that happened in about two seconds.

Tasks

Now let's do something more interesting

hello-world was just a proof-of-concept. Let's run something with a real shell inside it.

Task 1: Run Ubuntu — without installing Ubuntu

docker run -it ubuntu bash

Two new flags here:

  • -i — keeps the connection open (interactive)
  • -t — gives you a terminal prompt

You should see a prompt like root@abc123:/# — you're now inside a container running Ubuntu Linux. Even if you're on a Mac.

Try these commands from inside the container:

cat /etc/os-release
ls /
whoami

What do you see? You're root inside a stripped-down Ubuntu system.

Now try to break out of it on purpose:

node --version

You should get bash: node: command not found. Node isn't installed inside this container. That's isolation — the container has its own environment, completely separate from your machine.

When you're done exploring, exit the container:

exit

You're back on your machine. The container stopped.


Task 2: Run a one-liner without entering the container

You don't always need an interactive shell. You can pass a command directly:

docker run ubuntu echo "containers are weird and I like it"

Docker starts the container, runs your echo command, then exits. No prompt, no interaction.

Your turn: Run an Ubuntu container that prints today's date. The Linux command for that is date.

Write the full docker run command yourself. Don't look back at the example — just swap the command.

You should see the current date and time printed in your terminal, then the container exits.


Task 3: See what's on your machine now

docker images

This lists every image Docker has downloaded to your machine. You should see hello-world and ubuntu in the list. Note the SIZE column — hello-world is tiny (~13KB), Ubuntu is larger (~77MB).

docker ps -a

This lists all containers — including ones that have stopped. The -a flag means "all" (without it, you only see running containers). You should see your Ubuntu containers from the tasks above, all with STATUS Exited.

Notice each container has a random name like friendly_hopper or determined_poincare. Docker auto-generates these because you didn't name them. You'll fix that later.


That's your first real Docker session. You ran Ubuntu, got a shell inside it, ran commands, and exited — all without installing Ubuntu. Next up: understanding what's actually going on under the hood.

How this build unfolds

Containers from Scratch

Packaging Your App

Docker Compose

Ship It

Learn by building your own version.

Remix this public project to open the workspace, follow the guided build, and let the AI mentor teach you through the work instead of doing it for you.