Skip to main content

Command Palette

Search for a command to run...

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.

Updated
β€’16 min read
DevOps Week 5 – Docker Networking, Storage & Advanced Containerization
H
πŸ‘‹ Hi, I’m Hritik Ranjan β€” a B.Tech CSE student and a passionate tech enthusiast focused on Quality Engineering, AI/ML, Cybersecurity, and DevOps. πŸ’‘ I enjoy building and testing scalable, secure, and intelligent systems that solve real-world problems. My expertise and interests include: πŸ”Ή Quality Assurance & Testing Hands-on experience in manual and automation testing using Selenium & Java, ensuring high-quality and reliable applications. πŸ”Ή Artificial Intelligence & Machine Learning Exploring advanced algorithms and developing intelligent systems for practical use cases. πŸ”Ή Cybersecurity Focused on vulnerability assessment, security testing, and system hardening. πŸ”Ή Web Development Building responsive and user-friendly applications using modern technologies. πŸ”Ή Data Science Analyzing complex data to extract actionable insights. πŸ’Ό Key Projects: πŸš€ Blindness Detection System Applied computer vision techniques to detect blindness-related conditions. πŸš€ AI-Powered Rail Madad Enhancement Developed an intelligent complaint management system to improve railway customer service. πŸš€ Interactive Applications Built multiple projects like quiz apps, calculators, and productivity tools. 🌱 I’m continuously learning and improving my skills in DevOps, Cloud, and Automation to become a well-rounded engineer. 🀝 Open to collaborations, internships, and opportunities in QA, DevOps, AI/ML, and Cybersecurity. πŸ“« Let’s connect: hritikranjan1408@gmail.com

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 image

  • WORKDIR β†’ Working folder

  • COPY β†’ Copy project files

  • RUN β†’ Install dependencies

  • CMD β†’ 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

  1. Developer builds Django app

  2. DevOps writes Dockerfile

  3. Build Docker image

  4. Run container

  5. Deploy on AWS



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.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

  1. Write Dockerfile (multi-stage)

  2. Build app in first stage

  3. Copy only binary

  4. Use distroless image

  5. 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



βœ” 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 volume

  • target = 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

  1. Create volume

  2. Attach to container

  3. Store data

  4. Delete container

  5. 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:

  1. Bridge Network

  2. Host Network

  3. 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 πŸš€

  1. Create custom network

  2. Run frontend container

  3. Run backend container

  4. Allow only required communication

  5. 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. πŸš€

DevOps Learning Journey πŸš€

Part 5 of 14

Documenting my step-by-step journey of learning DevOps β€” from basics to advanced concepts. In this series, I’ll share weekly notes, hands-on practice, tools, and real-world insights as I grow in DevOps.

Up next

DevOps Week 5.1– Docker Interview Questions, Security & Real-World Scenarios

Master Docker interview concepts with beginner-friendly explanations on containers, networking, multi-stage builds, distroless images, security best practices, and real DevOps production challenges.

More from this blog

D

DevOps Journey by Hritik

14 posts

Started my DevOps journey from scratch, covering Linux, shell scripting, and a real-world AWS project for beginners.