Skip to content

Lesson 06 — Docker Basics

Imagine you’re developing a Python application.

It works perfectly on your laptop.

You send it to another developer.

Suddenly, it doesn’t work.

Why?

Because their computer has:

  • Different Python version
  • Different operating system
  • Missing libraries
  • Different configurations

This is known as the classic:

“It works on my machine.”

Docker solves this problem.

Docker packages an application together with everything it needs to run:

  • Application code
  • Libraries
  • Dependencies
  • Runtime
  • Configuration

This package is called a Container.

Containers ensure that applications run the same way everywhere.

Today, Docker is one of the most important technologies in Cloud Computing, DevOps, Platform Engineering, AI, and Cybersecurity.


After completing this lesson, you will be able to:

  • Understand containerization.
  • Learn Docker architecture.
  • Install Docker.
  • Work with Docker images.
  • Run Docker containers.
  • Create Dockerfiles.
  • Build Docker images.
  • Use Docker Hub.
  • Manage Docker volumes and networking.
  • Apply Docker in enterprise environments.

Docker is an open-source platform used to build, package, ship, and run applications inside lightweight containers.

Instead of installing software directly on an operating system, applications run inside isolated containers.

Docker provides:

  • Consistency
  • Portability
  • Isolation
  • Scalability
  • Fast deployment

Docker helps organizations:

  • Eliminate environment issues
  • Simplify deployments
  • Improve scalability
  • Speed up development
  • Standardize environments
  • Support microservices

Docker has become a standard technology in modern software development.


A container is an isolated environment that contains everything an application needs to run.

A container includes:

  • Application
  • Runtime
  • Libraries
  • Dependencies
  • Configuration Files

Unlike virtual machines, containers share the host operating system kernel, making them lightweight and fast.


Virtual Machine Docker Container
Includes Guest OS Shares Host OS
Larger Size Lightweight
Slower Startup Starts in Seconds
Higher Resource Usage Lower Resource Usage
Full Virtualization Operating System-Level Virtualization

Containers are more efficient for most modern applications.


Docker consists of several components.

Developer
Docker CLI
Docker Engine
Docker Images
Docker Containers

Each component plays a specific role in managing containers.


Docker includes:

  • Docker Client
  • Docker Engine
  • Docker Daemon
  • Docker Images
  • Docker Containers
  • Docker Registry

Together they provide a complete container platform.


A Docker Image is a read-only template used to create containers.

Think of an image as a blueprint.

Example:

Python Image
Run Container
Python Application

Images can be reused to create multiple containers.


Containers are running instances of Docker images.

Example:

Docker Image
Container 1
Container 2
Container 3

Each container runs independently.


Docker Hub is the public repository for Docker images.

Popular images include:

  • Ubuntu
  • Alpine
  • Python
  • Nginx
  • MySQL
  • PostgreSQL
  • Redis
  • Jenkins

Developers download images instead of creating everything from scratch.


Download Docker Desktop from:

https://www.docker.com/products/docker-desktop

Verify installation:

Terminal window
docker --version

Example:

Docker version 28.x.x

Run the Hello World container.

Terminal window
docker run hello-world

Docker automatically:

  • Downloads the image
  • Creates a container
  • Executes it
  • Displays the output

This confirms Docker is working correctly.


Download an image.

Terminal window
docker pull ubuntu

Download Python:

Terminal window
docker pull python

Images are stored locally after downloading.


Display downloaded images.

Terminal window
docker images

Example output:

python
ubuntu
nginx

Start an Ubuntu container.

Terminal window
docker run ubuntu

Interactive mode:

Terminal window
docker run -it ubuntu bash

The -it option provides an interactive terminal.


View active containers.

Terminal window
docker ps

View all containers:

Terminal window
docker ps -a

These commands help monitor container status.


Stop a running container.

Terminal window
docker stop container_id

Replace container_id with the actual container identifier.


Delete a container.

Terminal window
docker rm container_id

Removing unused containers keeps your environment clean.


Delete an image.

Terminal window
docker rmi image_name

Example:

Terminal window
docker rmi ubuntu

A Dockerfile defines how to build a Docker image.

Example:

FROM python:3.12
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python","app.py"]

Docker reads the instructions from top to bottom.


Build an image from a Dockerfile.

Terminal window
docker build -t myapp .

The -t flag assigns a name (tag) to the image.


Terminal window
docker run myapp

Docker creates a container from the image.


Containers are temporary.

Volumes provide persistent storage.

Example:

Terminal window
docker volume create app-data

Volumes allow data to survive container restarts and replacements.


Containers communicate using Docker networks.

Create a network:

Terminal window
docker network create app-network

Networking enables communication between multiple containers.


Docker Compose manages multi-container applications.

Example:

services:
web:
image: nginx
database:
image: mysql

Compose allows multiple services to start together using a single command.


Command Purpose
docker pull Download image
docker images List images
docker run Create container
docker ps List running containers
docker stop Stop container
docker rm Remove container
docker rmi Remove image
docker build Build image
docker logs View logs
docker exec Execute command inside container

Cloud Engineers use Docker for:

  • Microservices
  • Application Packaging
  • Serverless Development
  • Kubernetes Deployments
  • Cloud Migration

Containers simplify application portability across cloud providers.


DevOps Engineers use Docker to:

  • Build CI/CD pipelines
  • Standardize development environments
  • Deploy applications
  • Create reproducible builds
  • Run automated tests

Docker is a core DevOps technology.


Security teams use Docker for:

  • Security testing labs
  • Malware analysis
  • Sandboxed environments
  • Vulnerability scanning
  • Container security assessments

Containers provide isolated environments for testing and analysis.


AI Engineers use Docker to package:

  • Machine Learning Models
  • Jupyter Notebooks
  • TensorFlow Applications
  • PyTorch Projects
  • AI APIs

Containers ensure AI workloads run consistently across environments.


Avoid these mistakes:

  • Running containers as root unnecessarily.
  • Storing secrets inside Docker images.
  • Creating oversized images.
  • Ignoring image updates.
  • Leaving unused containers running.
  • Forgetting to persist important data with volumes.

Following best practices improves security and efficiency.


Professional teams:

  • Use official base images.
  • Keep images lightweight.
  • Scan images for vulnerabilities.
  • Use version tags.
  • Store secrets securely.
  • Use multi-stage builds.
  • Remove unused images regularly.
  • Monitor container health.

These practices improve reliability and security.


A DevOps Engineer deploys a web application.

Workflow:

Write Application
Create Dockerfile
Build Docker Image
Push Image to Registry
Deploy Container
Application Running

The same Docker image can run on a developer’s laptop, a test environment, or a production Kubernetes cluster without modification.


After completing this lesson, you should understand:

  • Docker.
  • Containers.
  • Images.
  • Docker Hub.
  • Dockerfile.
  • Docker Build.
  • Docker Run.
  • Docker Volumes.
  • Docker Networking.
  • Docker Best Practices.

Docker revolutionized software development by making applications portable, consistent, and easy to deploy.

By packaging applications and their dependencies into lightweight containers, Docker enables developers and operations teams to build, test, ship, and run software reliably across different environments.

Docker is now a foundational technology for Cloud Computing, DevOps, Artificial Intelligence, Cybersecurity, and modern application development.


➡️ Lesson 07 — Infrastructure as Code (IaC)

In the next lesson, you’ll learn how to automate infrastructure provisioning using Infrastructure as Code (IaC). You’ll explore Terraform, AWS CloudFormation, declarative infrastructure, version-controlled deployments, and enterprise infrastructure automation practices.