Post

Docker Installation And Compose

Docker Installation And Compose

πŸ”§ My Docker Compose πŸ”§


🐳 Docker Installation (Debian 10/11/12)

To install Docker on Debian, follow these steps:


πŸ”Ή Step 1: Update Your System

1
sudo apt update && sudo apt upgrade -y

πŸ”Ή Step 2: Install Required Packages

1
sudo apt install ca-certificates curl gnupg lsb-release -y

πŸ”Ή Step 3: Add Docker’s Official GPG Key

1
2
3
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | \
  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

πŸ”Ή Step 4: Set Up the Docker Repository

Replace $(lsb_release -cs) with your Debian codename if necessary (e.g., bullseye).

1
2
3
4
5
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

πŸ”Ή Step 5: Update Package List

1
sudo apt update

πŸ”Ή Step 6: Install Docker Engine

1
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

πŸ”Ή Step 7: Enable and Start Docker

1
2
sudo systemctl enable docker
sudo systemctl start docker

πŸ”Ή Step 8: Test Docker

1
sudo docker run hello-world

βœ… You should see a message confirming Docker is installed correctly.


πŸ”Έ (Optional) Run Docker as Non-Root User

1
sudo usermod -aG docker $USER

Log out and back in to apply group changes.


βš™οΈ Docker Compose Setup

Docker Compose lets you define and run multi-container Docker apps with a single command.


πŸ“ Step 1: Create a File Named docker-compose.yml

This file defines your services and configurations.


🧱 Step 2: Basic Structure

1
2
3
4
5
6
7
8
9
10
11
12
version: '3.8'

services:
  service_name:  # e.g., web, db
    image: image_name:tag
    ports:
      - "8080:80"
    volumes:
      - ./host_path:/container_path
    environment:
      - VAR_NAME=value
    restart: unless-stopped

🌐 Step 3: Example β€” Nginx + MySQL Stack

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
version: '3.8'

services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html
    restart: unless-stopped

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: examplepassword
    volumes:
      - db-data:/var/lib/mysql
    restart: unless-stopped

volumes:
  db-data:

▢️ Step 4: Run Docker Compose

1
docker-compose up -d
  • up β€” starts services.
  • -d β€” runs in detached/background mode.

To stop the stack:

1
docker-compose down

πŸ’‘ Tips

  • YAML is indentation-sensitive β€” use spaces, not tabs!
  • Keep your docker-compose.yml in the project root.
  • For advanced setups, define custom networks and volumes at the bottom.
  • Official reference: Docker Compose File Reference

This post is licensed under CC BY 4.0 by the author.