Docker has become extremely popular for self-hosting. It's a method of packaging your code, libraries, and dependencies into a single container. By using Docker Compose, you can run multiple interconnected services (like a database and a web app) with minimal setup.

1. Install Docker

The easiest way to install Docker on Raspberry Pi is to use the official convenience script. Run this command:

curl -sSL https://get.docker.com | sh

This script will handle the entire installation process and setup automatically.

2. Add User to Docker Group

By default, you need root privileges to run Docker commands. To run them as the 'pi' user, add yourself to the docker group:

sudo usermod -aG docker pi

3. Install Docker Compose

If you get a "docker-compose: command not found" error, it's because it's not installed by default. We'll install it using Python's package manager, Pip. First, install the necessary dependencies:

sudo apt-get install libffi-dev libssl-dev python3-dev python3 python3-pip -y

Configure Python Aliases (Optional)

To make python and pip point to their version 3 counterparts, edit your bashrc:

sudo nano ~/.bashrc

Add these lines at the top:

alias python=python3
alias pip=pip3

Save and reload:

source ~/.bashrc

Install via Pip

sudo pip3 install docker-compose

4. Verify Installation

Check the version to ensure everything is working:

docker-compose --version

5. Reboot

Finally, reboot your Pi to apply the group changes:

sudo reboot