DevOps Week 5 β Docker Networking, Storage & Advanced Containerization
Learn Docker networking, volumes, bind mounts, multi-stage builds, distroless images, and Django containerization with beginner-friendly DevOps notes and practical examples.

Dockerizing Django Application
πΉ 1. Django Basics (Very Important π₯)
π Django = Python web framework
β Project Structure
π settings.py
Configuration file
Database, apps, security settings
π urls.py
- Handles routing π URL β View mapping
π startapp
π Command to create new app
python manage.py startapp myapp
π Helps in modular development
πΉ 2. Why Containerize Django? π¦
π Problem without Docker:
Works on my system but not on server
Dependency issues
β Solution: Docker
π Package everything:
Code
Dependencies
Environment
π‘ Result: π Runs same everywhere
πΉ 3. Dockerfile for Django π₯
β Basic Dockerfile Example
FROM python:3.9
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
β Explanation:
FROMβ Base imageWORKDIRβ Working folderCOPYβ Copy project filesRUNβ Install dependenciesCMDβ Run application
πΉ 4. ENTRYPOINT vs CMD π₯ (Important)
β ENTRYPOINT
π Fixed main command π Cannot be overridden easily
β CMD
π Default arguments π Can be overridden
π Simple Difference:
ENTRYPOINT = Main command
CMD = Optional settings
πΉ 5. Build & Run Container π
β Build Image
docker build -t django-app .
β Run Container
docker run -p 8000:8000 django-app
β Port Mapping (Important)
π -p 8000:8000
First β Local port
Second β Container port
π Access app:
http://localhost:8000
πΉ 6. AWS Deployment π
β Steps:
Launch EC2
Install Docker
Run container
β Security Group (Important)
π Allow inbound traffic:
- Port: 8000
π Otherwise app wonβt open
πΉ 7. Networking Concept
π Container runs internally
π Port mapping exposes it outside
πΉ 8. DevOps Perspective π‘
π DevOps Engineer must:
Understand application flow
Know dependencies
Troubleshoot issues
β Not required:
- Full developer knowledge
β Required:
- Basic understanding of apps
πΉ 9. Real DevOps Workflow
Developer builds Django app
DevOps writes Dockerfile
Build Docker image
Run container
Deploy on AWS
Project Repo link - https://github.com/hritikranjan1/Docker-Zero-to-Hero.git
Optimize Docker Images (Advanced π)
πΉ 1. Problem with Large Docker Images β
π Normal Docker images:
Very large (500MB β 1GB+)
Contain:
OS
Build tools
Extra libraries
β Issues:
Slow deployment
High storage cost
Security risks
πΉ 2. Multi-Stage Docker Builds π₯
β What is it?
π Split Dockerfile into multiple stages
β Idea:
Stage 1 β Build application
Stage 2 β Run application
π Only copy required files
β Example Flow:
# Stage 1 (Build)
FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o app
# Stage 2 (Run)
FROM scratch
COPY --from=builder /app/app /app/app
CMD ["/app/app"]
β Benefits:
Removes unnecessary files
Reduces image size
Faster deployment
π Real Example
Without multi-stage β ~861 MB β
With multi-stage β ~150 MB β
πΉ 3. Distroless Images π₯
β What is Distroless?
π Minimal Docker image
π Contains:
Only app
Required runtime
β Does NOT contain:
Shell (bash)
curl / wget
package manager
β Benefits:
Very small size
More secure
Less attack surface
πΉ 4. Scratch Image (Extreme Case)
π FROM scratch = Empty image
π Only your app exists
π Real Result:
Final image size β 1.83 MB π²
Reduction β ~800x
Project Repo link - https://github.com/hritikranjan1/Docker-Zero-to-Hero.git
Final image size β 1.21 MB π²

πΉ 5. Security Benefits π
β Why Distroless is Secure?
No unnecessary tools
Hackers canβt run commands
Minimal vulnerabilities
β Compared to Ubuntu:
| Ubuntu Image | Distroless |
|---|---|
| Large size | Very small |
| More packages | Minimal |
| More vulnerabilities | Less |
πΉ 6. Real DevOps Use Case π‘
π In production:
Use multi-stage builds
Use distroless images
β Result:
Faster CI/CD
Better security
Lower cost
πΉ 7. Interview Answer
π If asked:
βHow did you optimize Docker images?β
π Answer:
Used multi-stage builds
Removed unnecessary dependencies
Switched to distroless images
Reduced size & improved security
πΉ 8. Real Workflow
Write Dockerfile (multi-stage)
Build app in first stage
Copy only binary
Use distroless image
Deploy container
Docker Volumes & Bind Mounts
πΉ 1. The Problem with Containers β
π Containers are temporary (ephemeral)
π If container is deleted:
- Data inside container is also deleted π’
β Example:
You run:
docker run mysql
π Store database data
But if container is removed:
docker rm container_id
β Database data is gone
πΉ 2. Solution β Persistent Storage
π To save data permanently:
Bind Mounts
Docker Volumes
πΉ 3. Bind Mounts π
β What is Bind Mount?
π Connect a folder from:
- Host machine β‘οΈ Container folder
β Example:
docker run -v /home/data:/app/data nginx
π Meaning:
/home/data= Host folder/app/data= Container folder
β Benefits
Easy for development
Direct access to files
β Problems
Depends on host OS path
Harder to manage in production
πΉ 4. Docker Volumes π₯ (Recommended)
β What are Volumes?
π Docker-managed storage system
π Data exists independently from container
β Benefits
Persistent storage
Easy backup
Portable
Better for production
β Key Advantage
π Even if container is deleted:
- Volume data remains safe β
πΉ 5. Volume Commands π οΈ
β Create Volume
docker volume create myvolume
β List Volumes
docker volume ls
β Inspect Volume
docker volume inspect myvolume
β Remove Volume
docker volume rm myvolume
πΉ 6. Mount Volume to Container
β Using --mount
docker run --mount source=myvolume,target=/app/data nginx
β Meaning:
source= Docker volumetarget= Container directory
πΉ 7. Verify Volume Connection π
π Check container details:
docker inspect container_id
π Shows:
Mounted volumes
Paths
πΉ 8. Bind Mount vs Volume π₯
| Feature | Bind Mount | Volume |
|---|---|---|
| Managed by Docker | β | β |
| Easy for local dev | β | β |
| Production ready | β | β |
| Portable | β | β |
πΉ 9. Real DevOps Use Cases π‘
β Databases
MySQL
PostgreSQL
π Data must survive container deletion
β Logs
Store application logs permanently
β Shared Data
Multiple containers can share same volume
πΉ 10. Best Practice π
π Use:
Bind Mounts β Development
Volumes β Production
πΉ 11. Real Workflow
Create volume
Attach to container
Store data
Delete container
Data still safe in volume β
πDocker Networking
π Bridge vs Host vs Overlay Networks | Secure Containers with Custom Bridge Network
πΉ 1. Introduction to Docker Networking π
When we run multiple containers, they often need to communicate with each other.
π Example:
Frontend container
Backend container
Database container
All these containers need networking to exchange data.
πΉ 2. Why Docker Networking is Important? π₯
Docker networking helps in:
β Communication between containers β Isolation of applications β Security β Connecting containers to internet β Multi-container applications
π‘ Real Example
Imagine:
Login Service Container
Payment Service Container
Database Container
π Login service should talk to database π Finance service should remain isolated for security
This is where Docker networking becomes important.
πΉ 3. Types of Docker Networks
Docker mainly provides:
Bridge Network
Host Network
Overlay Network
πΉ 4. Bridge Network (Default Network) π₯
β What is Bridge Network?
When Docker is installed, it automatically creates a virtual network called:
docker0
This acts like a bridge between containers.
β How it Works
Containers connected to the same bridge network can communicate with each other.
β Default Behavior
When you run containers normally:
docker run nginx
Docker automatically connects them to the default bridge network.
β Benefits
β Easy setup β Good for single-host communication β Containers can talk to each other
β Limitation
Less secure
All containers on same bridge may communicate
πΉ 5. Host Network π₯
β What is Host Networking?
In host networking:
π Container directly uses the host machineβs network.
β Meaning
Container does NOT get its own isolated network.
Instead:
Container uses Host IP directly
β Command Example
docker run --network=host nginx
β Advantages
β Faster performance β No bridge overhead
β Disadvantages
β Least secure β No isolation β Port conflicts possible
πΉ 6. Overlay Network π₯
β What is Overlay Network?
Overlay networking is used when containers run on:
π Multiple servers (multi-host)
β Used In:
Kubernetes
Docker Swarm
β Purpose
Allows containers on different servers to communicate.
π‘ Example
Container A β Server 1 Container B β Server 2
Overlay network connects them together.
πΉ 7. Custom Bridge Network π₯ (Very Important)
β Why Create Custom Network?
Default bridge allows many containers to communicate.
Sometimes we need:
Better isolation
More security
β Example Use Case
Finance application should not communicate with:
Login service
Public applications
πΉ 8. Create Custom Bridge Network
β Command
docker network create secure-network
β Verify Networks
docker network ls
πΉ 9. Run Container in Custom Network
β Example
docker run --network=secure-network nginx
Now this container belongs only to:
secure-network
πΉ 10. Benefits of Custom Bridge Networks
β Better security β Better isolation β Easier communication control β Containers communicate using names
πΉ 11. Container Communication Demo
β Same Network
Containers can communicate.
β Different Networks
Containers cannot communicate unless connected manually.
πΉ 12. Check Docker Networks
β List Networks
docker network ls
β Inspect Network
docker network inspect secure-network
Shows:
Connected containers
Network details
IP addresses
πΉ 13. Real DevOps Use Cases π‘
β Microservices
Different services communicate securely.
β Security Isolation
Sensitive apps separated from public apps.
β Kubernetes Networking
Overlay networks used heavily in clusters.
πΉ 14. Bridge vs Host vs Overlay π₯
| Feature | Bridge | Host | Overlay |
|---|---|---|---|
| Isolation | Medium | Low | High |
| Multi-host | β | β | β |
| Security | Good | Weak | Strong |
| Performance | Good | Best | Moderate |
| Use Case | Single Host | High Speed | Kubernetes |
πΉ 15. Important Interview Points π₯
β Why custom bridge network?
π Better isolation and security.
β Why host network is risky?
π Container directly uses host network.
β Where is overlay network used?
π Kubernetes & Docker Swarm.
πΉ 16. Real Workflow Example π
Create custom network
Run frontend container
Run backend container
Allow only required communication
Secure sensitive services
π Continue Your Learning Journey
Thank you for taking the time to read this article.
Technology is evolving rapidly, and continuous learning is one of the most valuable investments you can make in your career. Whether you're exploring DevOps, Cloud Computing, Artificial Intelligence, Cybersecurity, Software Development, Data Science, or Career Growth, the resources below can help you deepen your knowledge and stay ahead in the industry.
π Recommended Learning Platforms
π Coursera
Learn from world-renowned universities and industry leaders including Google, IBM, Stanford, Microsoft, Meta, and many more.
β Professional Certificates β Career-focused Learning Paths β AI & Machine Learning Programs β Cloud & DevOps Certifications β Business & Leadership Courses
π https://imp.i384100.net/k0KvbV
π» Udemy
One of the largest online learning platforms with practical, hands-on courses covering:
β DevOps & Kubernetes β Docker & Cloud Computing β AWS, Azure & GCP β Programming & Development β Cybersecurity & Ethical Hacking
π https://trk.udemy.com/MAL2MY
π DataCamp
A great platform for anyone interested in:
β Python Programming β SQL & Databases β Data Analytics β Machine Learning β Artificial Intelligence
Interactive learning paths and hands-on projects make it ideal for beginners and professionals alike.
π https://datacamp.pxf.io/nX4kER
π edX
Access high-quality courses and certifications from leading institutions such as:
β Harvard University β MIT β Berkeley β Microsoft
Perfect for learners seeking university-level education online.
π https://edx.sjv.io/POvVeN
π¨ Domestika
Enhance your creative skills with courses on:
β Graphic Design β Video Editing β Animation β Digital Marketing β Content Creation
π https://domestika.sjv.io/dynKAW
π οΈ Recommended Tools & Resources
π₯ AppSumo
Discover exclusive lifetime deals on:
β AI Tools β Productivity Software β Developer Utilities β Marketing Platforms β Business Applications
A must-have resource for developers, creators, freelancers, and entrepreneurs looking to save money while accessing premium tools.
π https://appsumo.8odi.net/L04a33
π Shopify
Looking to start an online business or launch an eCommerce store?
Shopify provides everything you need to build, manage, and scale an online business.
β Online Store Builder β Payment Integration β Inventory Management β Marketing Tools
π https://shopify.pxf.io/Vxv09k
π WordPress, WooCommerce & Jetpack
Create professional websites, blogs, and online stores with one of the most trusted web ecosystems in the world.
Ideal for:
β Personal Blogs β Portfolio Websites β Business Websites β eCommerce Stores
π https://automattic.pxf.io/Z6vR5W
π Language Learning Resources
π£οΈ Preply
Learn English and other languages through personalized one-on-one tutoring sessions with experts from around the world.
π https://preply.sjv.io/o4gBDY
π British Council English Online
Improve your professional communication skills and English fluency through structured learning programs.
π https://englishonline.sjv.io/9VOGa4
π§ Rosetta Stone
One of the most recognized language-learning platforms for immersive language acquisition.
π https://aff.rosettastone.com/X4OyqG
π§ͺ Science & Educational Resources
π¬ MEL Science
Interactive science kits and educational experiences designed to make STEM learning engaging and practical.
π https://imp.i328067.net/bk2beg
π Carson Dellosa Education
Educational materials and learning resources for students, teachers, and lifelong learners.
π https://carsondellosaeducation.sjv.io/E0JbjW
β€οΈ Support My Work
Creating detailed technical content, tutorials, guides, and learning resources takes significant time and effort.
If you find my articles helpful and would like to support my work, you can do so through the following platforms:
β Become a GitHub Sponsor
Support my open-source contributions, technical content, and community projects.
π https://github.com/sponsors/hritikranjan1
β Buy Me a Chai
Enjoying my content? Consider buying me a chai and supporting future tutorials, guides, and educational resources.
π https://www.chai4.me/hritikranjan
π¨βπ» Connect With Me
Hritik Ranjan
π‘ AI Enthusiast βοΈ DevOps Learner π Cybersecurity Advocate π» Software Developer
Connect & Follow
π GitHub: https://github.com/hritikranjan1
π LinkedIn: https://linkedin.com/in/hritikranjan1
π’ Found This Article Helpful?
If this article added value to your learning journey:
β
Share it with your network
β
Bookmark it for future reference
β
Follow for more DevOps, AI, Cloud, Cybersecurity, and Software Engineering content
Thank you for reading and being part of this learning journey.
Keep Learning. Keep Building. Keep Growing. π






