# Install Docker and compose-plugin

This guide explains how to install **Docker** and **Docker-Compose** on common Linux distributions.

Supported distributions in this guide:

- Debian / Ubuntu
- Arch Linux
- RHEL / Rocky / AlmaLinux / CentOS
- Fedora

Optional steps for allowing **non-root users** to run Docker are also included.

---

# Table of Contents

- Requirements
- Debian / Ubuntu Installation
- Arch Linux Installation
- RHEL / Rocky / AlmaLinux / CentOS Installation
- Fedora Installation
- Verify the Installation
- Allow Non-Root Docker Usage (Optional)
---

# Requirements

Before installing Docker, ensure that your system is updated.

```bash
sudo apt update
sudo apt upgrade
````

or on Arch:

```bash
sudo pacman -Syu
```

---

# Debian / Ubuntu Installation

Install Docker using the official repository.

## Install required packages

```bash
sudo apt install -y ca-certificates curl gnupg
```

## Add the Docker GPG key

```bash
sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/debian/gpg \
 | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg
```

## Add the Docker repository

```bash
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian \
$(. /etc/os-release && echo $VERSION_CODENAME) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```

## Install Docker

```bash
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

## Start Docker

```bash
sudo systemctl enable --now docker
```

---

# Arch Linux Installation

Arch provides Docker directly in the official repositories.

Install Docker:

```bash
sudo pacman -S docker docker-compose
```

Enable and start the service:

```bash
sudo systemctl enable --now docker
```

---

# RHEL / Rocky / AlmaLinux / CentOS Installation

Install required tools:

```bash
sudo dnf install -y dnf-plugins-core
```

Add the Docker repository:

```bash
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
```

Install Docker:

```bash
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

Start Docker:

```bash
sudo systemctl enable --now docker
```

---

# Fedora Installation

Install Docker from the official repository.

Add the repository:

```bash
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
```

Install Docker:

```bash
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

Start Docker:

```bash
sudo systemctl enable --now docker
```

---

# Verify the Installation

Check if Docker is installed correctly.

```bash
docker --version
```

Check Docker Compose:

```bash
docker compose version
```

Test Docker by running a simple container:

```bash
sudo docker run hello-world
```

If the container runs successfully, Docker is installed correctly.

---

# Allow Non-Root Docker Usage (Optional)

By default, Docker requires **root privileges** because it accesses the Docker socket.

To allow a normal user to run Docker commands without `sudo`, add the user to the `docker` group.

## Create the Docker group (if it does not exist)

```bash
sudo groupadd docker
```

## Add your user to the group

```bash
sudo usermod -aG docker $USER
```

## Apply the group changes

Log out and log back in, or run:

```bash
newgrp docker
```

## Test Docker without sudo

```bash
docker run hello-world
```

If it works without `sudo`, the permissions are configured correctly.

---

# Notes

* Running Docker without root privileges works by granting access to the Docker socket:

```
/var/run/docker.sock
```

* Users in the `docker` group effectively gain **root-level permissions**, so only trusted users should be added.