Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
beginner Free Docker Fundamentals · ⏱ 20 min

Run Your First Container

Scenario

You have Docker installed and a blank terminal. Your job is to get a real service running, reach it from your browser, and then tear it back down cleanly.

Learning objectives

  • Pull an image
  • Run a container in the background
  • Publish a port
  • View the container logs
  • Stop and remove the container

Before you start

Required software: Docker Engine 24+ or Docker Desktop

Prerequisites: Docker installed and running

  1. No download needed for this lab — you will type the commands directly.
  2. Confirm Docker works: docker run --rm hello-world.

Instructions

1. Pull the image

Pull a lightweight web server:

docker pull nginx:1.27-alpine

2. Run it with a published port

Run it detached and map host port 8080 to the container’s 80:

docker run -d --name first-web -p 8080:80 nginx:1.27-alpine

Open http://localhost:8080 — you should see the nginx welcome page.

3. Read the logs

Watch the access log as you refresh the page:

docker logs -f first-web

Press Ctrl-C to stop following.

4. Clean up

Stop and remove the container:

docker stop first-web && docker rm first-web

Hints

💡 The page won’t load

Check the port mapping in docker ps — the format is -p HOST:CONTAINER. The container listens on 80, so the right side must be 80.

💡 “port is already allocated”

Another process holds 8080. Pick a different host port, e.g. -p 8090:80.

Validate your work

From the lab folder, run:

bash validation/validate.sh

The script reads only your local Docker state, never transmits data off your machine, and returns a status code:

  • 0 — Lab successfully completed
  • 1 — Validation failed
  • 2 — Required dependency missing
  • 3 — Lab environment not running
  • 4 — Configuration error
  • 5 — Validation timed out

Note: validation targets Linux first. On Docker Desktop (macOS/Windows) some host-level checks (e.g. disk usage) may report differently; each script documents its limitations.

Solution

The full solution + troubleshooting explanation is available to signed-in learners. Try to solve it first — that’s where the learning is.

Reset the lab

  • docker rm -f first-web removes the container if it is still around.

Interview questions

  • What is the difference between `docker run` and `docker start`?
  • What does `-p 8080:80` mean, and which side is the host?
  • How do you see the logs of a running container?

Finished this lab?

Sign in to record your completion and track progress across the path. Completion is recorded server-side.

Related labs