Imagine this classic scenario:
The problem is environment inconsistency. Different machines have different operating systems, software versions, libraries, and configurations.
Docker solves this by using containerization.
Analogy: Shipping Containers
A read-only template. Think of it as a blueprint for creating containers. Images are immutable.
A running instance of an image. You can run multiple containers from the same image. They are isolated.
A text file with instructions for building images. Defines base image, dependencies, copied files, and startup command.
Core software including the Docker Daemon, REST API, and CLI.
A repository for images. Like GitHub but for Docker images.
Dockerfiledocker builddocker runExamples:
docker run hello-worlddocker run -p 8080:80 nginxContainerizing a Python Flask app:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, Docker World!'
if __name__ == '__main__':
app.run(debug = True, host = '0.0.0.0')FROM python: 3.9 - slim
WORKDIR / app
COPY requirements.txt.
RUN pip install - r requirements.txt
COPY. .
EXPOSE 5000
CMD["python", "app.py"]Flask==2.1.0| Feature | VM | Docker Container |
|---|---|---|
| Guest OS | Full OS | Shares Host Kernel |
| Size | GBs | MBs |
| Boot Time | Minutes | Seconds |
Docker solves "it works on my machine" by packaging apps and dependencies into containers. You learned about images, containers, Dockerfiles, workflows, commands, and best practices.