Docker Fundamentals

Lesson 2 of 6

Your First Docker Container

docker --version
docker run hello-world

docker run downloads the hello-world image from Docker Hub (a public registry of images) if you don't already have it, then starts a container from it.

Essential commands

docker pull nginx              # download an image without running it
docker images                  # list images you have locally
docker run -d -p 8080:80 nginx # run nginx in the background, map port 8080 -> 80
docker ps                      # list running containers
docker ps -a                   # list all containers, including stopped ones
docker stop <container_id>     # stop a running container
docker rm <container_id>       # remove a stopped container

-p 8080:80 maps port 8080 on your machine to port 80 inside the container, that's how you reach a containerized web server from your browser.

TIP

docker ps only shows running containers, add -a to see stopped ones too, a common source of confusion for beginners.

📝 First Container Quiz

Passing score: 70%
  1. 1.Which command lists currently running containers?

  2. 2.The flag -p 8080:____ maps port 8080 on your machine to port 80 inside the container.

  3. 3.docker ps shows stopped containers by default, without needing any extra flags.