Skip to main content

Course Progress

Loading...

Docker Fundamentals Review

Duration: 45 minutes
Module 4: Session 5.1

Learning Objectives

  • Understand the difference between containers and virtual machines
  • Master Docker architecture and components
  • Navigate Docker Hub for WordPress images
  • Apply Docker concepts to WordPress development

Introduction to Docker for WordPress

Docker revolutionizes WordPress development by providing consistent, reproducible environments. Whether you're working alone or in a team, Docker ensures everyone has the same development setup.

💡
Why Docker for WordPress?
Docker eliminates the "it works on my machine" problem by containerizing WordPress, PHP, MySQL, and all dependencies into portable, consistent environments.

Containers vs Virtual Machines

Understanding the difference between containers and VMs is crucial for effective Docker usage:

graph TB subgraph "Virtual Machine" VM1[Guest OS
Ubuntu] VM2[Guest OS
CentOS] VM3[Guest OS
Windows] HV[Hypervisor] HW1[Hardware/Host OS] VM1 --> HV VM2 --> HV VM3 --> HV HV --> HW1 end subgraph "Docker Containers" C1[WordPress
Container] C2[MySQL
Container] C3[phpMyAdmin
Container] DE[Docker Engine] HW2[Hardware/Host OS] C1 --> DE C2 --> DE C3 --> DE DE --> HW2 end

Key Differences

Aspect Containers Virtual Machines
Size Lightweight (MBs) Heavy (GBs)
Startup Time Seconds Minutes
Resource Usage Minimal High
Isolation Process level Complete OS
Portability Very High Limited

Docker Architecture

Docker uses a client-server architecture with several key components:

graph LR Client[Docker Client
CLI/GUI] Daemon[Docker Daemon
dockerd] Registry[Docker Registry
Docker Hub] Client -->|REST API| Daemon Daemon -->|Pull/Push| Registry subgraph "Docker Host" Daemon Images[Images
wordpress:latest
mysql:8.0
php:8.1-fpm] Containers[Containers
wp-site-1
wp-db-1] Volumes[Volumes
wp-content
mysql-data] Networks[Networks
wp-network] Daemon --> Images Daemon --> Containers Daemon --> Volumes Daemon --> Networks end

Core Components Explained

1. Docker Client

# The Docker client sends commands to the daemon
docker run wordpress:latest
docker ps
docker-compose up

2. Docker Daemon (dockerd)

The background service that manages Docker objects:

  • Listens for Docker API requests
  • Manages images, containers, networks, and volumes
  • Can communicate with other Docker daemons

3. Docker Images

# WordPress-specific images
docker pull wordpress:6.4-php8.2-apache
docker pull mysql:8.0
docker pull phpmyadmin:latest

4. Docker Containers

# Running WordPress container
docker run -d \
  --name my-wordpress \
  -p 8080:80 \
  -e WORDPRESS_DB_HOST=db \
  -e WORDPRESS_DB_USER=wpuser \
  -e WORDPRESS_DB_PASSWORD=wppass \
  wordpress:latest

Docker Hub and WordPress Images

Docker Hub is the world's largest container registry, hosting official WordPress images:

Official WordPress Images

Image Naming Convention

wordpress:[version]-[php_version]-[web_server]

Examples:
wordpress:latest           # Latest stable
wordpress:6.4              # Specific WordPress version
wordpress:6.4-php8.2       # With PHP version
wordpress:6.4-apache       # With Apache
wordpress:6.4-fpm          # PHP-FPM for nginx
wordpress:6.4-fpm-alpine   # Minimal Alpine Linux

Searching and Pulling Images

# Search for WordPress images
docker search wordpress

# Pull specific version
docker pull wordpress:6.4-php8.2-apache

# List downloaded images
docker images | grep wordpress

Image Layers and Efficiency

graph TD A[Base: debian:bullseye-slim
50MB] --> B[Add: Apache2
+30MB] B --> C[Add: PHP 8.2
+45MB] C --> D[Add: WordPress Core
+65MB] D --> E[Final Image: wordpress:6.4
Total: 190MB] style A fill:#e3f2fd style B fill:#bbdefb style C fill:#90caf9 style D fill:#64b5f6 style E fill:#42a5f5

Docker Best Practices for WordPress

  • Use specific tags:Avoid:latestin production. Usewordpress:6.4-php8.2-apache
  • Separate concerns:One container per service (WordPress, MySQL, Redis)
  • Persist data:Always use volumes for wp-content and database data
  • Environment variables:Store sensitive data in .env files, never in Dockerfiles
  • Network isolation:Create custom networks for your WordPress stack

Real World Example: Development Stack

A typical WordPress development environment using Docker:

# docker-compose.yml for WordPress development
version: '3.8'

services:
  wordpress:
    image: wordpress:6.4-php8.2-apache
    container_name: wp-dev
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DEBUG: 'true'
      WORDPRESS_DEBUG_LOG: 'true'
      WORDPRESS_DEBUG_DISPLAY: 'false'
    volumes:
      - ./wp-content:/var/www/html/wp-content
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    depends_on:
      - mysql
    networks:
      - wp-network

  mysql:
    image: mysql:8.0
    container_name: wp-mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - wp-network

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: wp-pma
    ports:
      - "8081:80"
    environment:
      PMA_HOST: mysql
      PMA_USER: root
      PMA_PASSWORD: rootpassword
    depends_on:
      - mysql
    networks:
      - wp-network

volumes:
  db-data:

networks:
  wp-network:
    driver: bridge

Docker Storage for WordPress

Understanding Docker storage is crucial for WordPress development:

Volume Types

graph LR subgraph "Bind Mounts" HF[Host Filesystem
/home/user/wp-site] CF1[Container
/var/www/html] HF -.->|Direct Mount| CF1 end subgraph "Named Volumes" DV[Docker Volume
wp-data] CF2[Container
/var/www/html] DV -.->|Managed by Docker| CF2 end subgraph "tmpfs Mounts" MEM[Memory] CF3[Container
/tmp/cache] MEM -.->|Temporary| CF3 end

WordPress-Specific Volume Strategies

volumes:
  # Development: Bind mount for live editing
  - ./themes/mytheme:/var/www/html/wp-content/themes/mytheme
  - ./plugins/myplugin:/var/www/html/wp-content/plugins/myplugin
  
  # Production: Named volumes for persistence
  - wp-content:/var/www/html/wp-content
  - wp-uploads:/var/www/html/wp-content/uploads
  
  # Database: Always use named volumes
  - mysql-data:/var/lib/mysql

Docker Networking for WordPress

Docker networks enable secure communication between WordPress components:

# Create a custom network for WordPress
docker network create wp-network

# Run containers on the network
docker run -d --name wordpress --network wp-network wordpress
docker run -d --name mysql --network wp-network mysql

# Containers can now communicate using hostnames
# WordPress can connect to mysql using hostname "mysql"
Network Security
Containers on the same network can communicate, but are isolated from other networks. This provides security by default.

Practice Exercise

Let's verify your Docker installation and explore WordPress images:

💻
Try It Now
  1. Check Docker version:docker --version
  2. Search for WordPress images:docker search wordpress --limit 5
  3. Pull WordPress image:docker pull wordpress:6.4-php8.2-apache
  4. Inspect the image:docker inspect wordpress:6.4-php8.2-apache
  5. View image layers:docker history wordpress:6.4-php8.2-apache

Additional Resources