Container Foundations · 8 min read · Intermediate
Images, Containers & docker run
Understand how Docker isolates apps using Linux namespaces, and run your first containerized web server.
What you'll learn
- Distinguish a read-only image (blueprint) from a running container (instance)
- Publish container ports to the host using -p host:container
- Run containers detached (-d), view logs, and clean up with --rm
Docker packages your code, runtime, and system libraries into a portable image so “it works on my machine” becomes “it works identically on every laptop and cloud server.”
- Image: Immutable read-only template (like a class).
- Container: A lightweight running process created from an image (like an object instance).
Fill-in-the-Blank Exercise
Run Detached Nginx Container
Run nginx in detached mode (-d) mapping host port 8080 to container port 80.
docker -d 8080:80 --name web nginx:alpineLive Command Reference Lab
Bashdocker_basics.sh
Expected OutputClick “Run Live” to compile with GNU Bash
# Start container in background on localhost:8080 docker run -d -p 8080:80 --name web nginx:alpine # Inspect running containers & logs docker ps docker logs -f web # Stop and remove cleanly docker rm -f web
Check Your Understanding
Score: 0 / 1
1. In docker run -p 3000:8080 myapp, which port do you open in your browser on the host machine?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.