Setup Raspberry Pi Home Lab with docker
In this article, we will set up a Raspberry Pi home lab, which covers all the details from Hardware setup, OS installation and docker setup.
Hardware & Prerequisites
- Raspberry Pi 4
- MicroSD card
- USB Solid State Drive (SSD) (Optional)
Essentially, Raspberry Pi is booting from the MicroSD card. However, it is recommended to boot from the USB SSD for better performance and reliability.
In this section, we will install Raspberry Pi OS on the MicroSD card and configure it to boot from the USB SSD.
Install Raspberry Pi OS on MicroSD card
Download the Raspberry Pi Imager from the official website.
Insert the MicroSD card into your computer.
Open the Raspberry Pi Imager and select the Raspberry Pi OS desktop version. Then follow the on-screen instructions to write the image to the MicroSD card.
Once the image is written, insert the MicroSD card into the Raspberry Pi and power it on.
Boot from USB SSD
- After booting from the MicroSD card, open the terminal and run the following command to update the bootloader:
sudo apt update
sudo apt full-upgrade
sudo rpi-eeprom-update
# Reboot the Raspberry Pi
sudo reboot
Use the raspberry pi os desktop built-in imager to write the image to the USB SSD.
Accessories
->Imager
.After rebooting, open the terminal and run
sudo raspi-config
. Then navigate toAdvanced Options
->Boot loader version
->E1 Latest ...
Advanced Options
->Boot Order
->USB Boot
.
Turn off the Raspberry Pi and remove the MicroSD card. Then power it on. The Raspberry Pi should boot from the USB SSD.
Configure Raspberry Pi
Enable Raspberry Pi SSH:
top-left icon
->Preferences
->Raspberry Pi Configuration
->Interfaces
->SSH
->Enable
.Enable
Connect Raspberry Pi
beta feature if needed. Check the official documentation for more details.
- Install
screenfetch
to display system information:
sudo apt install screenfetch
You might also want to check all the system status using the following command:
- CPU temperature:
vcgencmd measure_temp
- disk partition:
df -h
,lsblk
andsudo fdisk -l
- memory usage:
free -h
Install Docker & Portainer
# Install docker
sudo apt install docker.io
# Install docker-compose
sudo apt install docker-compose
Above command will install docker on your Raspberry Pi. You can verify the installation by running docker --version
.
Next, we will install Portainer to manage the docker containers.
Firstly, create a docker-compose.yml
file:
version: '3'
services:
portainer:
container_name: portainer
image: portainer/portainer-ce:latest
ports:
- 9000:9000
volumes:
- /home/eric/Docker/portainer/data:/data
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
Then run the following command to start the Portainer container:
docker-compose up -d
Now you can access the Portainer dashboard by navigating to http://<raspberry-pi-ip>:9000
then rock and roll!