π³ 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
πΉ 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
up
β starts services.-d
β runs in detached/background mode.
To stop the stack:
π‘ 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