0
0
Dockerdevops~30 mins

Why containers matter in Docker - See It in Action

Choose your learning style9 modes available
Why Containers Matter
📖 Scenario: You are a developer who wants to share a simple web app with your friend. But your friend has a different computer setup. You want to make sure the app runs exactly the same on both computers.
🎯 Goal: Build a Docker container that runs a simple web server. This shows how containers keep apps working the same everywhere.
📋 What You'll Learn
Create a Dockerfile that uses the official Python image
Add a simple Python web server script inside the container
Expose port 8000 to access the web server
Run the container and see the web server output
💡 Why This Matters
🌍 Real World
Containers let developers share apps that run the same on any computer, avoiding setup problems.
💼 Career
Understanding containers is key for DevOps roles to deploy and manage applications reliably.
Progress0 / 4 steps
1
Create a simple Python web server script
Create a file named app.py with this exact code: from http.server import SimpleHTTPRequestHandler, HTTPServer server = HTTPServer(('0.0.0.0', 8000), SimpleHTTPRequestHandler) server.serve_forever()
Docker
Need a hint?

This script starts a simple web server on port 8000 that serves files from the current folder.

2
Write a Dockerfile to containerize the app
Create a file named Dockerfile with these exact lines: FROM python:3.12-slim COPY app.py /app.py EXPOSE 8000 CMD ["python", "/app.py"]
Docker
Need a hint?

The Dockerfile tells Docker which base image to use, copies your app, opens port 8000, and runs the app.

3
Build the Docker image
Run the exact command docker build -t simple-web . in your terminal to build the Docker image named simple-web.
Docker
Need a hint?

This command tells Docker to build an image from the current folder and name it simple-web.

4
Run the Docker container and check output
Run the exact command docker run -p 8000:8000 simple-web and then open http://localhost:8000 in your browser. Write SimpleHTTPServer as the output you see in the terminal logs.
Docker
Need a hint?

Running the container starts the web server. The terminal shows SimpleHTTPServer in the logs.