DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Full Lecture Part 1: Understanding Docker from an Enterprise Perspective

Most beginners learn Docker as:

docker run nginx
Enter fullscreen mode Exit fullscreen mode

and think they know Docker.

A DevOps Engineer with 6 years of experience sees Docker very differently.

Docker is not just a tool to run containers.

Docker is:

  • Application packaging technology
  • Infrastructure standardization technology
  • Deployment technology
  • CI/CD technology
  • Resource optimization technology
  • Cloud-native foundation

Today almost every company using:

  • AWS ECS
  • AWS EKS
  • Kubernetes
  • Azure AKS
  • Google GKE

is using Docker concepts underneath.

Before learning commands, you must understand why Docker exists.


The Problem Before Docker

Imagine a company in 2012.

The development team creates a Java application.

The application works perfectly on the developer's laptop.

The developer gives the code to Operations.

Operations deploys it to production.

Suddenly:

Application Failed
Enter fullscreen mode Exit fullscreen mode

Developer says:

It works on my machine.
Enter fullscreen mode Exit fullscreen mode

Operations says:

It doesn't work in production.
Enter fullscreen mode Exit fullscreen mode

This became one of the biggest problems in software engineering.

Why?

Because every machine was different.

Developer Laptop:

Ubuntu 22
Java 17
Maven 3.9
Enter fullscreen mode Exit fullscreen mode

Production Server:

Ubuntu 18
Java 11
Maven 3.6
Enter fullscreen mode Exit fullscreen mode

Different libraries.

Different versions.

Different dependencies.

Different configurations.

Result:

Deployment Failure
Enter fullscreen mode Exit fullscreen mode

This happened thousands of times every day across the industry.

Docker was created to solve this problem.


What Exactly Is Docker?

Docker packages everything an application needs into a single package.

Think of Docker as a shipping container.

Before shipping containers:

Boxes
Chairs
Tables
Electronics
Food
Enter fullscreen mode Exit fullscreen mode

Everything was loaded differently.

Shipping was slow.

Shipping was expensive.

Shipping was difficult.

Then shipping containers were invented.

Now everything goes inside one standard container.

No matter what is inside.

A truck can move it.

A train can move it.

A ship can move it.

Same idea with Docker.

Docker creates a standardized container for software.

Inside that container:

Application
Libraries
Dependencies
Runtime
Configuration
Enter fullscreen mode Exit fullscreen mode

Everything needed to run.


Visualizing Docker

Think about a NodeJS application.

Without Docker:

Developer Laptop
|
NodeJS
Express
Libraries
Configuration
Enter fullscreen mode Exit fullscreen mode

Production:

Production Server
|
NodeJS
Express
Libraries
Configuration
Enter fullscreen mode Exit fullscreen mode

Everything must be installed again.

Now Docker:

Docker Image
|
NodeJS
Express
Libraries
Configuration
Application
Enter fullscreen mode Exit fullscreen mode

Build once.

Run anywhere.


What Is a Container?

This is the most common interview question.

A container is NOT Docker.

A container is NOT an image.

A container is:

A running process
Enter fullscreen mode Exit fullscreen mode

Think of this carefully.

When you start Chrome:

Chrome Process
Enter fullscreen mode Exit fullscreen mode

When you start VS Code:

VS Code Process
Enter fullscreen mode Exit fullscreen mode

When Docker starts a container:

Container Process
Enter fullscreen mode Exit fullscreen mode

A container is simply a process isolated from other processes.


What Makes Containers Special?

Linux provides special technologies:

Namespaces

Namespaces create isolation.

Container A sees:

Its own processes
Its own network
Its own filesystem
Enter fullscreen mode Exit fullscreen mode

Container B sees:

Its own processes
Its own network
Its own filesystem
Enter fullscreen mode Exit fullscreen mode

Even though both run on the same server.


Control Groups (cgroups)

Cgroups control resources.

Example:

Container A:

2 CPUs
4GB RAM
Enter fullscreen mode Exit fullscreen mode

Container B:

1 CPU
2GB RAM
Enter fullscreen mode Exit fullscreen mode

Linux ensures containers stay inside those limits.

As a DevOps Engineer you will use this daily.


Why Containers Are Better Than Virtual Machines

Let's compare.

Traditional Virtual Machine:

Physical Server
|
Hypervisor
|
VM1 -> Guest OS
VM2 -> Guest OS
VM3 -> Guest OS
Enter fullscreen mode Exit fullscreen mode

Each VM has:

Linux Kernel
System Services
Libraries
Application
Enter fullscreen mode Exit fullscreen mode

Huge amount of duplication.


Container Model:

Physical Server
|
Host Linux
|
Docker Engine
|
Container A
Container B
Container C
Enter fullscreen mode Exit fullscreen mode

All containers share:

Host Kernel
Enter fullscreen mode Exit fullscreen mode

Result:

Faster

VM:

2-5 minutes startup
Enter fullscreen mode Exit fullscreen mode

Container:

2-10 seconds
Enter fullscreen mode Exit fullscreen mode

Smaller

VM:

10-20 GB
Enter fullscreen mode Exit fullscreen mode

Container:

100 MB
Enter fullscreen mode Exit fullscreen mode

More Efficient

One server may run:

20 VMs
Enter fullscreen mode Exit fullscreen mode

or

100+ Containers
Enter fullscreen mode Exit fullscreen mode

depending on workload.

This is why companies adopted containers.


Docker Architecture

When you type:

docker run nginx
Enter fullscreen mode Exit fullscreen mode

many things happen.


Docker Client

The command line.

Example:

docker run
docker build
docker pull
Enter fullscreen mode Exit fullscreen mode

This is only the interface.


Docker Daemon

The actual engine.

Service running in background:

dockerd
Enter fullscreen mode Exit fullscreen mode

Receives requests.

Creates containers.

Creates networks.

Creates volumes.

Pulls images.


Docker Registry

Stores images.

Examples:

Think:

GitHub stores code

Registry stores images
Enter fullscreen mode Exit fullscreen mode

What Is a Docker Image?

A Docker image is a blueprint.

Not running.

Not active.

Just instructions.

Example:

Ubuntu Image
Enter fullscreen mode Exit fullscreen mode

contains:

Ubuntu Filesystem
Libraries
Packages
Enter fullscreen mode Exit fullscreen mode

Still not running.


Example:

When you buy a house blueprint:

Blueprint ≠ House
Enter fullscreen mode Exit fullscreen mode

Same concept:

Image ≠ Container
Enter fullscreen mode Exit fullscreen mode

Image vs Container

Image:

Template
Enter fullscreen mode Exit fullscreen mode

Container:

Running Instance
Enter fullscreen mode Exit fullscreen mode

Example:

One image:

nginx
Enter fullscreen mode Exit fullscreen mode

Can create:

Container1
Container2
Container3
Container4
Enter fullscreen mode Exit fullscreen mode

Exactly like:

One blueprint
Many houses
Enter fullscreen mode Exit fullscreen mode

How a DevOps Engineer Uses Docker Daily

A developer writes code.

Example:

React
NodeJS
Java
Python
Enter fullscreen mode Exit fullscreen mode

DevOps engineer creates:

Dockerfile
Enter fullscreen mode Exit fullscreen mode

Dockerfile describes:

How to build application
Enter fullscreen mode Exit fullscreen mode

Then:

docker build
Enter fullscreen mode Exit fullscreen mode

creates image.

Then:

docker push
Enter fullscreen mode Exit fullscreen mode

pushes image into registry.

Then:

ECS
Kubernetes
EKS
Enter fullscreen mode Exit fullscreen mode

pull image and deploy.

This is the heart of modern CI/CD.


Enterprise Flow

Real production architecture:

Developer
     |
GitHub
     |
Jenkins/GitHub Actions
     |
Docker Build
     |
Docker Image
     |
ECR
     |
ECS/EKS
     |
Application Running
Enter fullscreen mode Exit fullscreen mode

Every major company follows this concept.

As a senior DevOps engineer you must understand:

  1. How images are built
  2. How containers run
  3. How networking works
  4. How storage works
  5. How security works
  6. How orchestration works
  7. How monitoring works
  8. How troubleshooting works

These topics are what separate a junior Docker user from a 6-year DevOps engineer.

Top comments (0)