Skip to main content

Command Palette

Search for a command to run...

Docker Fundamentals: A Beginner-Friendly Guide

Learn Docker fundamentals, architecture, images, containers, and essential commands with practical examples.

Updated
5 min read
Docker Fundamentals: A Beginner-Friendly Guide

Introduction

As applications grow, managing dependencies, libraries, and environment configurations becomes challenging. A common issue developers face is:

"It works on my machine but not on the server."

Docker solves this problem by packaging applications and their dependencies into portable containers that run consistently across different environments.

In this article, we'll learn the fundamentals of Docker, understand its architecture, and explore commonly used Docker commands.


What is Docker?

Docker is an open-source containerization platform that enables developers to build, package, and run applications in isolated environments called containers.

A Docker container includes:

  • Application Code

  • Runtime

  • Libraries

  • Dependencies

  • Configuration Files

This ensures that the application behaves the same way regardless of where it runs.


Three-Tier Application Architecture

Most modern applications follow a three-tier architecture:

Frontend
   ↓
Backend
   ↓
Database

Example

  • Frontend: React, Angular, Vue

  • Backend: Python, .NET, Java

  • Database: MySQL, PostgreSQL, MongoDB

Docker allows each layer to run in separate containers while communicating with one another.


Why Do We Need Docker?

Before Docker:

  • Different environments cause compatibility issues.

  • Dependency versions may differ between systems.

  • Application deployment becomes complex.

With Docker:

  • Consistent environments

  • Faster deployment

  • Better resource utilization

  • Simplified application management

  • Easy scalability

Build Once, Run Anywhere

Docker allows developers to build an application once and run it anywhere without worrying about platform-specific issues.


Docker Terminology

Dockerfile

A Dockerfile is a text file containing instructions used to create a Docker image.

Example:

FROM python:3.11

WORKDIR /app

COPY . .

RUN pip install -r requirements.txt

EXPOSE 80

CMD ["python", "app.py"]

Docker Image

A Docker Image is a read-only template that contains:

  • Application Code

  • Runtime

  • Libraries

  • Dependencies

Examples:

nginx:latest
python:3.11
mysql:8

Docker Container

A Docker Container is a running instance of a Docker image.

Docker Image
      ↓
Docker Container

Containers are lightweight, portable, and isolated.


Docker Registry

A Docker Registry stores Docker images.

Popular registries:

  • Docker Hub

  • Amazon ECR

  • Azure Container Registry

  • Google Container Registry


Virtualization vs Containerization

Before containers, virtualization was widely used.

Virtualization

Application
Application
Application
      ↓
Guest OS
Guest OS
Guest OS
      ↓
Hypervisor
      ↓
Host Machine

Advantages

  • Strong isolation

  • Multiple operating systems on one machine

Disadvantages

  • Higher resource consumption

  • Larger storage requirements

  • Slower startup times


Containerization

Docker uses containerization.

Application
Application
Application
      ↓
Docker Engine
      ↓
Host Operating System
      ↓
Host Machine

Advantages

  • Lightweight

  • Faster startup

  • Better resource utilization

  • Reduced storage usage


Docker Architecture

Docker consists of several components:

Docker Client
       ↓
Docker Daemon
       ↓
Images & Containers
       ↓
Docker Registry

Docker Client

The Docker Client is the command-line interface used by users.

Examples:

docker build
docker run
docker pull
docker push

Docker Daemon (dockerd)

The Docker Daemon runs in the background and manages:

  • Images

  • Containers

  • Networks

  • Volumes


Docker Engine

Docker Engine is the core runtime responsible for running containers.

Main components:

  • Docker Client

  • Docker Daemon

  • containerd


Docker Registry

Stores and distributes Docker images.

Example:

docker pull nginx

The image is downloaded from Docker Hub.


Docker Workflow

Docker follows a simple workflow:

Dockerfile
    ↓
Docker Image
    ↓
Docker Container

Or

Code
 ↓
Build
 ↓
Image
 ↓
Run
 ↓
Container

Common Docker Commands

Check Running Containers

docker ps

Check All Containers

docker ps -a

Search Images

docker search nginx

Test Docker Installation

docker run hello-world

Launch Ubuntu Container

docker run -it ubuntu bash

Options:

  • -i Interactive

  • -t Terminal


Run Nginx Container

docker run -d -p 80:80 nginx

Options:

  • -d Detached Mode

  • -p Port Mapping


Run Nginx with Custom Name

docker run -d -p 80:80 --name nginx-demo nginx

Run MySQL Container

docker run -d \
-e MYSQL_ROOT_PASSWORD=root \
mysql

Stop Container

docker stop <container-id>

Remove Container

docker rm <container-id>

Force Kill Container

docker kill <container-id>

Creating Your First Docker Image

Dockerfile

FROM python:3.11

WORKDIR /app

COPY . .

RUN pip install -r requirements.txt

EXPOSE 80

CMD ["python", "app.py"]

Build Image

docker build -t python-app .

Explanation:

  • build → Create image

  • -t → Tag image

  • python-app → Image name

  • . → Current directory


Run Container

docker run -d -p 8080:80 python-app

Application will be available at:

http://localhost:8080

Key Takeaways

  • Docker is a containerization platform.

  • Containers are lightweight and portable.

  • Docker solves dependency and environment issues.

  • Docker follows the workflow: Dockerfile → Image → Container.

  • Containers share the host OS kernel, making them more efficient than virtual machines.

  • Docker simplifies application deployment and scaling.


Conclusion

Docker has become an essential tool for modern application development and DevOps practices. By understanding Docker fundamentals, images, containers, architecture, and common commands, you build a strong foundation for advanced topics such as Docker Compose, Kubernetes, CI/CD pipelines, and cloud-native applications.

If you're starting your DevOps journey, Docker is one of the first technologies you should master.