In these days, I am thinking on my old raspberry pi projects. Actually, there a lot of projects that I made for different purposes, however these projects are right now so messy to manage because a lot of them wrote directly for raspberry pi and they include some kind of README files to explain how to setup an environment on the raspberry pi. In order to get rid of this messy structure of the projects, I am planning to containerize my projects. Briefly my old way to manage my project was this:
Therefore the very first step that i can take for this purpose is containerizing my apps. By doing this it will solve these issues:’
After this step, one thing that i should do is just pulling adocker images and running them with right parameters.
After containerizing my app, i need to prepare an SD card
If you are developing linux based embedded projects like me i think all of us follow some common “mistakes”. The first thing that i want to mention is
However this kind of flow is very messy to manage as you can see. I face these issues with this way:
First of all, i will assume that you have already containerized your application and pushed it to the a docker registry (hopefully with a ci/cd pipeline). Also i will explain these steps for Raspbery Pi. If you are ready to go then we can take a step further.
Download RPi OS Lite image from the official website and extract the archieve with an uncompression tool. After getting .img file we can write it with Balena Etcher.
After flashing the image to the sd card, we need to create some configuration files because we want to do headless setup.
pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0
3.
Righ now, we should have a working version of a linux operating system working on Raspberry Pi. We need to enable remote ssh support (it is usally called headless setup). First, we need to remove and re-insert the sd card to the computer.
Purpose: Running docker containers on Raspberry pi
Righ now, we should have a working version of a linux operating system working on Raspberry Pi. We need to enable remote ssh support (it is usally called headless setup). First, we need to remove and re-insert the sd card to the computer.
pi:$6$c70VpvPsVNCG0YR5$l5vWWLsLko9Kj65gcQ8qvMkuOoRkEagI90qi3F/Y7rm8eNYZHW8CY6BOIKwMH7a3YYzZYL90zf304cAHLFaZE0
sudo apt install -y docker docker-compose
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker $USER
If you want to check whether the docker service is running or not you can use docker run hello-world
.
docker-compose.yml
sudo nano /etc/systemd/system/docker-auto-pull-up.service
[Unit]
Description=Docker Compose
After=network.target docker.service
[Service]
WorkingDirectory=/boot
Type=simple
Restart=no
User=root
ExecStart=/usr/bin/env sh -c "sleep 10 && cd /boot && docker-compose pull && docker-compose up"
[Install]
WantedBy=multi-user.target
sudo systemctl enable docker-auto-pull-up.service