Back to Engineering Notes
DockerEngineering Note

1. Install Docker Packages and Start Docker Service

Docker is a platform to build, run, and manage containers.

🎯 Objective

Learn how to:

Install Docker CE (Community Edition)
Install Docker Compose
Start and enable Docker service

🧠 What is Docker?

Docker is a platform to build, run, and manage containers.

👉 Containers allow you to:

Package app + dependencies together
Run consistently across environments
Simplify deployment

🧠 What is Docker Compose?

Docker Compose is used to:

Run multiple containers together
Define services using a docker-compose.yml file

👉 Example:

Laravel + MySQL + Redis + Nginx

⚙️ Architecture Overview

plain text
Application (Laravel / Node.js)
        ↓
Docker Container
        ↓
Docker Engine
        ↓
Host OS (Linux)

🧩 Supported OS

CentOS / RHEL / Rocky Linux
Ubuntu / Debian

# 🚀 Step 1: Install Docker CE


🔹 For RHEL / CentOS / Rocky Linux

1. Install Required Packages

plain text
sudo yum install -y yum-utils

2. Add Docker Repository

plain text
sudo yum-config-manager \
--add-repo https://download.docker.com/linux/centos/docker-ce.repo

3. Install Docker CE

plain text
sudo yum install -y docker-ce docker-ce-cli containerd.io

🔹 For Ubuntu / Debian

1. Update Packages

plain text
sudo apt update

2. Install Dependencies

plain text
sudo apt install -y ca-certificates curl gnupg

3. Add Docker GPG Key

plain text
sudo install-m0755-d /etc/apt/keyrings
curl-fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg--dearmor-o /etc/apt/keyrings/docker.gpg

4. Add Repository

plain text
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu$(lsb_release -cs) stable" | \
sudotee /etc/apt/sources.list.d/docker.list > /dev/null

5. Install Docker

plain text
sudo apt update
sudo apt install-y docker-ce docker-ce-cli containerd.io

# ▶️ Step 2: Start and Enable Docker Service

plain text
sudo systemctl enable --now docker

🔍 Verify Installation

plain text
docker --version
plain text
sudo systemctl status docker

🧪 Test Docker

plain text
sudo docker run hello-world

👉 If successful → Docker is working ✅


# 🔧 Step 3: Install Docker Compose


🔹 Install Docker Compose Plugin (Recommended)

plain text
sudo apt install docker-compose-plugin# Ubuntu

# OR

sudo yum install docker-compose-plugin# RHEL/CentOS

🔍 Verify

plain text
docker compose version

🧩 Example: Simple Docker Compose File

plain text
version:"3.9"

services:
  app:
    image: nginx
    ports:
      -"80:80"

Run:

plain text
docker compose up-d

🧠 Key Concepts


⚠️ Best Practices

🔒 Avoid running containers as root
📦 Use official images
🔄 Keep images updated
🧪 Test with hello-world
🔑 Add user to docker group (optional):
plain text
sudo usermod-aG docker$USER

🧩 Real-World Use Case

👉 Your stack:

Laravel App → container
MySQL → container
Redis → container
Nginx → container

👉 Managed via:

plain text
docker compose up-d

📌 Summary

Docker = container runtime
Docker Compose = multi-container orchestration
Service must be started + enabled
Ready for local dev & deployment