Hi there, I want to share a very easy way to emulate a Raspberry Pi device through Docker, this have been very useful for me and now I’ll show how to do it with a couple of command lines. According to the GitHub repository, DockerPi is: “A Virtualised Raspberry Pi inside a Docker image. This is not just a Raspian Docker image, it’s a full ARM based Raspberry Pi virtual machine environment“. They mention Raspbian but actually you can run any OS images based on Debian/Raspbian/Ubuntu. More information about DockerPi here.
Installing & Setting Up
I’ll be running DockerPi in a KVM-based VPS from Wishosting, you can get one here, I recommend the KVM HDD Limited one. The VPS runs a fresh Debian 11 (Bullseye) up-to-date installation. You must install Docker, some QEMU tools and screen, you can do that by execute this command line:
apt install docker.io qemu-utils screen -y
Once that’s completed, do a quick test by executing:
screen -S DockerPi docker run -it lukechilds/dockerpi
Now you will be running a Raspberry Pi 1 Docker container, the login details are: pi as username and raspberry as password. Check more information about the Raspberry Pi device with this single command line:
uname -a && cat /etc/os-release | head -n 1 && lscpu && free
You can upgrade Raspian as a regular Raspberry Pi 1 device but since this is a quick test, let’s power it off by execute:
Running Raspberry Pi 2/3 Devices
DockerPi can emulate a Raspberry Pi 1/2/3 device by adding the device at the end of the command line, quick examples:
- Run a Raspberry Pi 1/Zero: docker run -it lukechilds/dockerpi
- Run a Raspberry Pi 2: docker run -it lukechilds/dockerpi pi2
- Run a Raspberry Pi 3: docker run -it lukechilds/dockerpi pi3
Note: there’s a known issue with the halt command line regarding Raspberry Pi 2/3 devices, it won’t power off, instead you must kill the container. That’s why I run DockerPi through screen, you can kill the screen, and therefore, the docker container by pressing: CRTL + A, then press k, then press y.
Customizing OS Images
The most requested feature of my Berryboot Custom OS Images project, is to get up-to-date OS images that doesn’t require an upgrade process from the Raspberry Pi device end. Let’s say you want to do that and also want to install nginx and some essential packages, in that way, you don’t have to upgrade nor install them once you download the already-upgraded OS image.
As an example: I’ll download Raspberry Pi OS Image (minimal) latest release and install the following packages: aria2 bc bleachbit cmatrix dialog dosfstools ffmpeg git htop jq netcat nfs-common ntfs-3g nginx p7zip-full pigz pv screen sshfs sshpass whois.
First, you must download Raspberry Pi OS image latest release, by the time of writing this post, the latest Raspberry Pi OS image is: 2021-10-30, do that by executing:
wget https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-11-08/2021-10-30-raspios-bullseye-armhf-lite.zip; unzip *raspios*.zip; rm -f *raspios*.zip
Once the download is completed, you must add additional space to the image, resize the image by executing:
qemu-img resize -f raw 2021-10-30-raspios-bullseye-armhf-lite.img +2G
Now you can run the Raspberry Pi 3 device by executing the following command line:
docker run -it -v /root/2021-10-30-raspios-bullseye-armhf-lite.img:/sdcard/filesystem.img lukechilds/dockerpi:vm pi3
Once that’s completed, login as pi username and raspberry as password. Expand the filesystem by using the raspi-config tool:
Then select: 6-Advanced Options > A1-Expand Filesystem
Once that’s completed, select: Finish and reboot the system. As soon as you see the “Reboot failed — System halted” message, kill the screen by pressing: CRTL + A, then press k, then press y.
Run the container and login again, now you can upgrade the system and install the essential packages by executing:
sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt install -y aria2 bc bleachbit cmatrix dialog dosfstools ffmpeg git htop jq netcat nfs-common ntfs-3g nginx p7zip-full pigz pv screen sshfs sshpass whois
Once that’s completed, halt the system by executing:
As soon as you see the “Reboot failed — System halted” message, kill the screen by pressing: CRTL + A, then press k, then press y.
From this point, you now have an upgraded Raspberry Pi OS with pre-installed custom packages, you can either download it to yourself or you can redistribute it to your friends/teams. Quick suggestions: if you’re going to use the custom OS image as standalone installation, I recommend PiShink to compress the OS image. If you’re going to use the OS image through Berryboot, you can follow these steps. Also, you can setup a webserver with a single command line as I described it in this post.
Have a question? Leave a comment.
382 total views, 4 views today