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:

  1. Wrote the app and push it to some git remote host.
  2. Burn the sd card image for the target platform.
  3. Connect the board via SSH.
  4. Install dependencies of the project manually.
  5. Clone the repository
  6. Build the source code and install it to system.
  7. Create systemd service files for them.
  8. Let it to work.

Therefore the very first step that i can take for this purpose is containerizing my apps. By doing this it will solve these issues:’

  1. I will get rid of time consuming setup process. 2.

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:

  1. Manual management of dependencies and versions.
  2. Updating the firmware of the edge located devices.

How to get benefits of Docker

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.

  1. Burn the SD card image

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.

  1. Create an empty ssh.txt in boot partition of the sd card.
  2. Create userconf.txt file in the boot partition of the sd card with this content:


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.

Installing Docker and Docker Compose to Raspberry Pi

Purpose: Running docker containers on Raspberry pi

  1. Download Raspberry Pi OS Lite image.
  2. Extract the archive (if it was compressed which means file extension look like .img.xz)
  3. Write the downloaded image into the sd card via a tool like balenaEtcher

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.

  1. Go to the boot partition of the sdcard and create a file whose name is ssh.txt (Please double check the extension of the file).
  2. Create a file named userconf.txt. And place this into the file.
  1. Insert the sdcard to the Raspberry Pi and connect it to the power and your local network via ethernet.
  2. Find the ip address of the Raspberry Pi with a tool like Advanced IP Scanner or Angry Ip scanner.
  3. Connect to the RPi via SSH. (You can use ssh command directly or PuTTY in Windows) (username: pi, password:raspberry) (ssh pi@

Installing docker and docker-compose

  1. Install docker and docker-compose: sudo apt install -y docker docker-compose
  2. Enable docker service: sudo systemctl enable docker
  3. Start docker service: sudo systemctl start docker
  4. Add current user to docker group: sudo usermod -aG docker $USER
  5. Disconnect and connect again

If you want to check whether the docker service is running or not you can use docker run hello-world.

Adding Dockercompose to boot partition

  1. Insert the SD card and create a file called docker-compose.yml
  2. If you need other files place them also in there

Adding auto pull and up service

  1. Insert SD card to RPi again and connect it via SSH.
  2. Create a service file in sudo nano /etc/systemd/system/docker-auto-pull-up.service
Description=Docker Compose docker.service

ExecStart=/usr/bin/env sh -c "sleep 10 && cd /boot && docker-compose pull && docker-compose up"

  1. Press Ctrl+X and y and Enter
  2. Enable the service sudo systemctl enable docker-auto-pull-up.service