Phase 1: Understanding the "Why" - Part 2

2. Dependency Conflicts Problem

What Are Dependencies?

Before we dive into conflicts, let's understand dependencies with a simple example.

Simple Example:

Imagine you want to make a sandwich. To make a sandwich, you DEPEND on:

  • Bread
  • Butter
  • Vegetables
  • Cheese

These ingredients are your "dependencies" - things you need to complete your task.

In Software:

When you build an application, it DEPENDS on other software/libraries:

Your Web App depends on:
├── Python (programming language)
├── Flask (web framework)
├── SQLAlchemy (database library)
├── Requests (for API calls)
└── Pillow (for image processing)

Each of these is a "dependency" - your app needs them to work.


The Dependency Conflict Problem

The Scenario:

You're a developer working on TWO different projects on the same computer:

Project A (Old Client Project):

  • Needs Python 3.7
  • Needs Django version 2.2
  • Needs Pillow version 7.0

Project B (New Modern Project):

  • Needs Python 3.11
  • Needs Django version 4.2
  • Needs Pillow version 10.0

The Problem:

Your computer can typically have only ONE version of Python installed globally. Same with libraries.

So when you install Python 3.11 for Project B, Project A breaks because it needs Python 3.7!

When you install Django 4.2 for Project B, Project A breaks because it needs Django 2.2!

Real-Life Example:

Imagine you have:

  • An old DVD player that only works with old TVs (needs red/white/yellow cables)
  • A new PlayStation 5 that only works with modern TVs (needs HDMI cable)
  • But you only have ONE TV

If you connect the old cables for the DVD player, PS5 won't work. If you connect HDMI for PS5, DVD player won't work.

You can't use both at the same time on one TV!

Similarly:

Your Computer:
├── Install Python 3.7 for Project A ✓
│   └── Project A works ✓
│   └── Project B breaks ✗ (needs Python 3.11)
│
└── Install Python 3.11 for Project B ✓
    └── Project B works ✓
    └── Project A breaks ✗ (needs Python 3.7)

Another Practical Example

Scenario:

You're building:

E-commerce Website:

  • Uses Library X version 1.0
  • Library X version 1.0 has a function called calculate_price()

Blog Website:

  • Uses Library X version 2.0
  • Library X version 2.0 CHANGED the function to get_price() (different name!)

What Happens:

Install Library X version 1.0:
✓ E-commerce works (calls calculate_price())
✗ Blog breaks (tries to call get_price() but it doesn't exist)

Install Library X version 2.0:
✓ Blog works (calls get_price())
✗ E-commerce breaks (tries to call calculate_price() but it doesn't exist)

You're stuck! You can't run both projects on the same computer.


How Docker Solves Dependency Conflicts

Docker creates separate, isolated boxes for each project.

Think of it like this:

Instead of one TV, you now have TWO separate rooms:

Room 1 (Container 1):
├── Old TV
├── DVD Player
├── Old cables
└── Project A runs here with Python 3.7 and Django 2.2

Room 2 (Container 2):
├── Modern TV
├── PlayStation 5
├── HDMI cable
└── Project B runs here with Python 3.11 and Django 4.2

Both can exist at the same time without interfering with each other!

In Docker Terms:

Container 1 (Project A):
├── Python 3.7
├── Django 2.2
├── Pillow 7.0
└── Completely isolated environment

Container 2 (Project B):
├── Python 3.11
├── Django 4.2
├── Pillow 10.0
└── Completely isolated environment

Both running on the SAME computer simultaneously! ✓

Visual Example

WITHOUT DOCKER:
Your Computer (One Shared Environment)
├── Python 3.11 (only one version allowed)
├── Django 4.2 (only one version allowed)
└── All projects fight for the same resources ✗

WITH DOCKER:
Your Computer
├── Container 1 (Project A's Box)
│   ├── Python 3.7
│   ├── Django 2.2
│   └── Isolated ✓
│
├── Container 2 (Project B's Box)
│   ├── Python 3.11
│   ├── Django 4.2
│   └── Isolated ✓
│
└── Container 3 (Project C's Box)
    ├── Node.js 14
    ├── React 17
    └── Isolated ✓

All running together without conflicts! ✓

Key Takeaway

Docker lets you run multiple projects with different (even conflicting) dependencies on the same computer by isolating each project in its own container.

Each container thinks it's the only thing running on the computer - it has its own versions of everything it needs!

No comments:

Post a Comment

Phase 1: Understanding the "Why" - Part 3

3. Environment Consistency Problem What is an "Environment"? First, let's understand what we mean by "environment" i...