Containers Explained
"It works on my machine" happens because environments differ: Python versions, system libraries, OS packages. A container packages your app with everything it needs, so it runs the same on your laptop, CI and production.
Containers vs virtual machines
| Virtual machine | Container | |
|---|---|---|
| Includes | a full guest operating system | just your app and its libraries |
| Shares the host kernel | no | yes |
| Size | gigabytes | tens to hundreds of megabytes |
| Start time | minutes | seconds |
Containers are isolated processes, not tiny computers. That makes them light, but it also means a misconfigured container (running as root, with host access) can affect the host.
Vocabulary
- Image: a read-only template built from a
Dockerfile, made of layers. - Container: a running instance of an image.
- Registry: where images are stored and shared (Docker Hub, GitHub Container Registry, cloud registries).
- Volume: persistent storage that survives container restarts.
- Network: how containers talk to each other.
Install and try
Install Docker Desktop (Windows/macOS) or Docker Engine (Linux), then:
docker run --rm hello-world
docker run --rm -it python:3.12-slim python -c "print('hi from a container')"
docker run -d --name web -p 8080:80 nginx # visit http://localhost:8080
docker ps # running containers
docker logs web
docker stop web && docker rm web
docker images
-p 8080:80 maps port 8080 on your machine to port 80 inside the container. --rm deletes the container when it exits. -d runs it in the background.
Why developers and businesses use containers
- Consistency across development, CI and production.
- Isolation: different apps can use different Python or Node versions on one server.
- Portability: the same image runs on Render, Fly.io, AWS ECS, Kubernetes or a VPS.
- Reproducible builds: the Dockerfile documents exactly how the app is assembled.
Check yourself
- What is the difference between an image and a container?
- Why are containers lighter than virtual machines?
- What does
-p 8080:80do?
आपकी प्रगति केवल इसी ब्राउज़र में सहेजी जाती है।
समीक्षा के लिए भेजें (10 अंक)