Putting A Pi In A Container

Docker and other containerization applications have changed a lot about the way that developers create new software as well as how they maintain virtual machines. Not only does containerization reduce the system resources needed for something that might otherwise be done in a virtual machine, but it standardizes the development environment for software and dramatically reduces the complexity of deploying on different computers. There are some other tricks up the sleeves as well, and this project called PI-CI uses Docker to containerize an entire Raspberry Pi.

The Pi container emulates an entire Raspberry Pi from the ground up, allowing anyone that wants to deploy software on one to test it out without needing to do so on actual hardware. All of the configuration can be done from inside the container. When all the setup is completed and the desired software installed in the container, the container can be converted to an .img file that can be put on a microSD card and installed on real hardware, with support for the Pi models 3, 4, and 5. There’s also support for using Ansible, a Docker automation system that makes administering a cluster or array of computers easier.

Docker can be an incredibly powerful tool for developing and deploying software, and tools like this can make the process as straightforward as possible. It does have a bit of a learning curve, though, since sharing operating system tools instead of virtualizing hardware can take a bit of time to wrap one’s mind around. If you’re new to the game take a look at this guide to setting up your first Docker container.

16 thoughts on “Putting A Pi In A Container

  1. Hnm, not sure where the ansible relation comes from, but it has nothing to do with docker. Its a way to install a system, be it docker or bare metal.

    Also not convinced if thats the best idea to install a container either. You install your container via a dockerfile. Thats where you describe how your container is assembled. Now you have a containerfile, that describes how to install ansible and then nees to learn and manage ansible as a nother layer to install the container.

    1. Hi Steve,

      I’m the original author of the PI-CI project. I see a lot of confusion in the comments here, let me explain what, how and why.

      This project intends to provide a virtualized environment that can be used to prepare “golden images” for the Raspberry Pi. The container image is there so that the project is pull & play.

      Once a user has started the virtual raspberry Pi, only THEN Ansible is used to configure the virtual raspberry pi. Ansible can be used to start the VM, install and configure software in the VM, shut down the VM and then export the (Raspberry) image. The image can then be flashed to an SD card. This way, once the real Pi starts, everything is already there.

      The article has some things wrong, which is why you may have been confused.

  2. I gotta say this is a bit misleading:
    1) The obvious: Ansible is not a Docker automation system. It’s an infrastructure as code tool for automating configuration management, software installation etc.
    2) Can we really say that they’re using Docker to containerize a Raspberry Pi? Essentially they’re building an image that has the Raspian image, QEMU and a Python application that manages it. Git repo says “Prepare Raspberry Pi 3, 4 & 5 configurations using a virtual machine.” It’s actually a QEMU VM.

    It just doesn’t sit right with me. Docker containers have a usage purpose and VMs have another usage purpose. Combining these two this way is just giving me migraines. I can see why they’re using Docker, essentially as a package manager, but this is just wrong on so many levels. I think they were so preoccupied with whether or not they could, they didn’t stop to think if they should.

    It’s definitely a hack though, I gotta give them that.

    1. People confuse containerizaton with virtualization all the time and that’s very much Docker’s fault for conflating the two to begin with. If you want to run the Pi image on different hardware, creating a VM for it is the way to go.

      Related, check out packer.io for automating VM image

      But it has to be docker so we can run this under Kubernetes!

        1. Except a Linux container like an LXC or LXD are not the same as a docker container. They each do things differently and have different advantages/disadvantages.

          That’s like saying ARM is an alternative to x86.
          At a conceptual level it sure is.
          You could absolutely choose one or the other when you start creating something.
          You might even be able to convert individual things frome one to the other.
          But it is not going to be a 1 to 1 replacement.

  3. Never used Docker, but 90% of PI projects are requiring a phisical connection to some external devices/sensors/whatever. How just emulating a PI helps with that?

    1. The point seems to be to set up the pi using the container and then create an image to stick on an actual pi, not to use the container as if you were using a pi, in that case you might as well just use the host system.

    2. I understand the idea that the Pi exists to be a platform that uses those gpio pins for something. I also feel this way.

      But that just isn’t the case most of the time today.
      This is clearly a software hacker project, and to them, an SBC is just “small ARM Linux machine” not necessarily “how I’m talking to spi bus”.

  4. I guess it’s cool if your organization’s too cheap to by every developer a Pi…. where else might they be cutting costs?

    I guess it’s also a cool way to basically reverse engineer a Pi, to run Pi software that was originally ported from common architectures back.

    I guess the only way it makes sense is if the software + docker setup is less resource intensive than another setup… but that would require an almost insane level of quality programing not seen since [insert Star Wars reference here and reference the date].

    I guess it’s just an over engineered ARM compiler.

    I guess it’s cool because I’d be able to see, in a perfect virtual environment, how much better the 5 is than the 4 I currently own. So yes, cool, because I’m jealous… and too cheap to get a 5 while I have a 3B+ and a 4 not seeing permanent use.

    I guess it’s use is limited to software, the real feat would be to get that 40 pin GPIO off a USB dongle that would be cheaper than a Pi. Yes, I know, some advanced user’s going to point out that you can control a Pi remotely but a dongle would cost even less. Or imaging using a Pi Zero (xyz verson, much cheaper than a 4 or a 5) with it’s headers and connecting it to a Pi 5 emulator. I could get behind that.

    I guess I’m always looking for the lowest resource VM for any given app I want to isolate. And every so often I consider purchasing a Pi Zero 2 W just for that, and it’s lower power consumption which you do not get in a VM.

    I guess I remember looking into a RPi emulator a while back and remember reading something about using QEMU to do it, just felt too complicated at the time, a docker image would be easier. But what about the overhead? Docker requirements, the emulating software requirements, the Pi hardware… just to run apps (current and maintained) that were probably native to other systems?

    Overall, I think it’s cool. It needs polishing, like if you’re going to do all that work, why not throw in a few other popular SBCs, maybe turn it into a personal SBC designer tool. Keeping in mind that RaspbianOS exists for x86 so if I really want to see my Ryzen fly, I already know what to do.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.