AcademyContainment Breach: The Architect's ShipZone 1: The Isolation Chamber

Lesson 2: Your First Container

Time to get your hands dirty. Let's run real containers and understand how they work from the inside.

Running a Container: docker run

The docker run command creates and starts a container from an image:

docker run ubuntu echo "Hello from inside a container!"

What just happened:

  1. Docker checked if the ubuntu image exists locally.
  2. If not, it pulled it from Docker Hub (the public registry).
  3. It created a container from the image.
  4. It ran echo "Hello from inside a container!" inside it.
  5. The container stopped (its job was done).

Interactive Mode: -it

To get a shell inside a container (like SSH-ing into a server):

docker run -it ubuntu bash
  • -iInteractive (keep stdin open).
  • -tTTY (allocate a terminal).

You're now inside the container! It's a fresh, isolated Ubuntu environment. Type exit to leave.

Common docker run Flags

| Flag | Purpose | Example | |------|---------|---------| | -it | Interactive terminal | docker run -it ubuntu bash | | -d | Detached (background) | docker run -d nginx | | --name | Give the container a name | docker run --name web nginx | | --rm | Auto-remove when stopped | docker run --rm ubuntu echo hi | | -p | Map a port | docker run -p 8080:80 nginx | | -e | Set environment variable | docker run -e DB_HOST=localhost app |

Listing Containers

docker ps              # Show RUNNING containers only
docker ps -a           # Show ALL containers (including stopped)
docker ps -q           # Show only container IDs

The Container vs. Image Mental Model

Think of it like baking:

  • Image = The recipe 📜 (read-only blueprint)
  • Container = The cake 🎂 (a running instance of the recipe)

You can bake many cakes from one recipe. Each cake is independent — decorating one doesn't change the others.

docker run -d --name web1 nginx    # Cake 1
docker run -d --name web2 nginx    # Cake 2
docker run -d --name web3 nginx    # Cake 3
# All from the same recipe (nginx image)
booting...

Mission Objective

Launch and explore your first containers:

  1. Dive in: Run docker run -it ubuntu bash to enter an Ubuntu container.
  2. Check the fleet: Run docker ps to see running containers.
  3. See everything: Run docker ps -a to see all containers, including stopped ones.

Mission Control

Run an Ubuntu container interactively

Expected Command

docker run -it ubuntu bash

List running containers

List all containers including stopped ones