Ever heard "It works on my machine"? Docker solves that.
Here’s a quick step-by-step to get started with Docker—no fluff, just the essentials. 🚀
🛠 Prerequisites
Docker installed: https://www.docker.com/products/docker-desktop
Basic knowledge of terminal/command line
1️⃣ Create a Simple App
Let’s build a basic Python app.
docker-tutorial/
├── app.py
└── requirements.txt
📝 app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from Docker!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
📝 requirements.txt
flask
2️⃣ Create a Dockerfile
In the same folder, create a file called Dockerfile (no extension):
# Use an official Python image
FROM python:3.11-slim
# Set the working directory
WORKDIR /app
# Copy files to container
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# Run the app
CMD ["python", "app.py"]
3️⃣ Build Your Image
Open terminal in your project folder and run:
docker build -t hello-docker .
4️⃣ Run Your Container
docker run -d -p 5000:5000 hello-docker
Go to your browser and visit: http://localhost:5000 🎉
🧹 Clean Up
Stop and remove all containers:
docker ps -a
docker stop <container_id>
docker rm <container_id>
Top comments (0)