📅 Day 7: Docker Distroless Image + Flask App Deployment (Hands-On)

Today’s goal was to go deeper into Docker by working with Distroless images and deploying a small Flask web app using a custom Dockerfile.
---
🚀 What I Learned
✅ What Are Distroless Images?
Distroless images are minimal Docker images without a full Linux distribution.
They contain only the application and its runtime, nothing more.
Why use them?
Smaller image size (faster pull/push)
Improved security (reduced attack surface)
Better performance
🧪 Real-World Example:
Imagine you're building a banking microservice where security is a top priority. A distroless image ensures there’s no shell access or package manager, reducing risk.
---
🔧 Project: Flask App in Distroless Docker Image
Step-by-step:
1. Create a Flask App (app.py)
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from Distroless Flask!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
2. Requirements File
Flask==2.3.2
3. Dockerfile (Multi-stage build using Distroless)
# Stage 1: Builder
FROM python:3.10-slim as builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Stage 2: Distroless runtime
FROM gcr.io/distroless/python3
WORKDIR /app
COPY --from=builder /app /app
CMD ["app.py"]
4. Build & Run Docker
docker build -t flask-distroless .
docker run -p 5000:5000 flask-distroless
5. Access the app
Open your browser: http://localhost:5000
---
🧠 What I Understood Clearly
Difference between __name__ and __main__
Multi-stage Docker builds
How to access apps running inside containers
Security benefits of distroless images
---
📌 Challenges I Faced
Typing __name__ correctly with underscores 😅
Error due to case-sensitive From in Dockerfile (FROM is correct)
Ensuring proper file structure while copying in multi-stage build
---
🔄 Tomorrow’s Plan
Push this project to GitHub
Connect this Docker container to an NGINX reverse proxy
Start experimenting with Ansible playbooks
---
🙌 Stay Connected
I’m documenting this journey daily — follow along and let’s grow together in Cloud + DevOps!
📍Hashnode: DevOpsWithSukaran
🔗 GitHub: github.com/Sukaran-233
💼 LinkedIn: mahajansukran
Subscribe to my newsletter
Read articles from Sukaran Mahajan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sukaran Mahajan
Sukaran Mahajan
🚀 Aspiring Cloud & DevOps Engineer | AWS Free Tier User | Learning by Building Hi, I’m Sukaran Mahajan — I am working as System Administrator and currently on a focused journey to become job-ready in AWS Cloud, DevOps, and Infrastructure automation. With a growing foundation in Linux, Git, Docker, and Terraform, I’m documenting everything I learn to help others and strengthen my understanding. 💡 Currently Learning: • AWS (EC2, S3, IAM, VPC, Lambda) • Docker, Terraform & Ansible • CI/CD tools (GitHub Actions, Jenkins) • Kubernetes basics 🛠 Hands-on Projects: • Flask + Docker App Deployment • Terraform-based AWS Infrastructure • EC2 SSH automation & S3 access control 📝 I also write beginner-friendly technical blogs on Hashnode: 🔗 https://devopswithsukaran.hashnode.dev 💼 Open to internships, DevOps/cloud roles, and collaborative projects. Let’s connect and grow in tech together! 🔗