Lesson 02: Getting Started with Docker, Conda, and Python Environments on Raspberry Pi 5
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
Add yourself to the docker group
sudo usermod -aG docker $USER
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.
2.2 Install Conda on Raspberry Pi 5
Install Conda on Raspberry Pi 5
1. Install Conda (Miniforge)
- Download Miniforge:
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
- Install Miniforge:
bash Miniforge3-Linux-aarch64.sh
- Restart the terminal or activate conda:
source ~/miniforge3/bin/activate
- Verify installation:
conda --version
2. Update Conda
conda update -n base -c conda-forge conda
3. Create a Conda Environment
conda create -n hailo python=3.10
conda activate hailo
4. Install Python Packages
- Install numpy and pip:
conda install numpy pip
- Install TensorFlow Lite:
pip install tflite-runtime
- Install HailoRT (Python bindings):
pip install /opt/hailo/extra/hailo_python/hailo*.whl
5. Test the Installation
- Test HailoRT:
python -c "import hailo; print('HailoRT OK!')"
- Test TensorFlow Lite:
python -c "import tflite_runtime.interpreter; print('TFLite OK!')"
Common Conda Commands Reference
Common Conda Commands and Parameters
1. Environment and Package Commands
Description
Command | Description |
---|---|
conda create -n myenv python=3.10 |
Create environment named myenv with Python 3.10 |
conda create --prefix /path/to/myenv python=3.10 |
Create environment at a specific folder |
conda env list |
List all environments |
conda activate myenv |
Activate environment by name |
conda activate /path/to/myenv |
Activate environment by folder path |
conda deactivate |
Deactivate current environment |
conda install numpy |
Install package (e.g., numpy) |
conda install -n myenv numpy |
Install package in specific environment |
conda install --prefix /path/to/myenv numpy |
Install package in environment by folder |
conda list |
List packages in current environment |
conda list -n myenv |
List packages in named environment |
conda list --prefix /path/to/myenv |
List packages in environment at folder |
conda update numpy |
Update package |
conda remove numpy |
Remove package |
conda remove -n myenv --all |
Delete environment by name |
conda remove --prefix /path/to/myenv --all |
Delete environment at specific folder |
conda env export > env.yml |
Export environment to YAML file |
conda env create -f env.yml |
Create environment from YAML file |
conda search numpy |
Search for package (numpy) |
conda info |
Show Conda installation info |
conda update conda |
Update Conda itself |
conda config --add channels conda-forge |
Add conda-forge channel |
2. Key Parameters
Parameter | Description |
---|---|
-n myenv |
Specify environment name |
--prefix /path/to/myenv |
Specify environment folder path |
-c conda-forge |
Install from conda-forge channel |
-y |
Automatic yes to prompts |
--all |
Apply to all (e.g., delete all packages in env) |
-f env.yml |
Use YAML file for environment creation |
3. Usage Examples
# Create environment by name
conda create -n testenv python=3.9
# Create environment at a specified folder
conda create --prefix /home/pi/project_env python=3.10
# Activate named environment
conda activate testenv
# Activate environment by folder
conda activate /home/pi/project_env
# Install numpy in current environment
conda install numpy
# Install matplotlib in environment at folder
conda install --prefix /home/pi/project_env matplotlib
# Remove environment at folder
conda remove --prefix /home/pi/project_env --all