Lesson 02: Docker on Pi5
2.1 Installing Docker on Raspberry Pi 5
Installing Docker on Raspberry Pi 5
There are two main methods to install Docker on your Raspberry Pi 5. Choose the one that best suits your needs.
Option 1: Using Docker's Convenience Script
This is the quickest and simplest method to install Docker:
- Download Docker's convenience script:
curl -fsSL https://get.docker.com -o get-docker.sh
- Run the script to install Docker:
sudo sh get-docker.sh
Option 2: Manual Installation
This method offers more control but involves additional steps. Follow these instructions to install Docker using its official APT repository:
- Update the package list and install prerequisites:
sudo apt-get update sudo apt-get install ca-certificates curl
- Add Docker's official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
- Add Docker's repository to APT sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
- Install Docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
After completing these steps, Docker will be installed and ready to use on your Raspberry Pi 5.
Next Steps
After completing either installation method, Docker will be installed and ready to use on your Raspberry Pi 5. You can verify the installation by running:
docker --version
2.2 Changing the Docker Root Direction
Relocating the Docker root directory on a Raspberry Pi 5 involves changing the directory where Docker stores all its data, including images, containers, volumes, and configurations. Docker uses /var/lib/docker as the root directory by default. If you want to move this directory to a different location, follow these steps:
Step 1: Stop the Docker Service
sudo systemctl stop docker
Step 2: Create the New Docker Directory
sudo mkdir -p /ssd/docker
Step 3: Move the Existing Docker Data
sudo rsync -aP /var/lib/docker/ /ssd/docker/
The rsync command is used here to ensure that all files are copied correctly and that the ownership and permissions are preserved.Step 4: Update Docker Configuration
sudo nano /etc/docker/daemon.json
Add or modify the following line to specify the new directory:
{
"data-root": "/ssd/docker"
}
Step 5: Start the Docker Service
sudo systemctl start docker
Step 6: Verify the Change
sudo docker info | grep "Docker Root Dir"
Docker Root Dir: /ssd/docker
This command should show the new directory, confirming that Docker uses it correctly.Step 7: Clean Up (Optional)
sudo rm -rf /var/lib/docker
You have successfully relocated the Docker root directory on your Raspberry Pi 5. Docker should now store all its data in the new directory you specified. This can be particularly useful if you're running low on space on the default filesystem or have a faster or larger storage option.