Leon Anavi
IT Tips && Tricks

Mobile & Embedded

Created: 29.01.2025 06:45 Last Modified: 29.01.2025 06:47 Views: 87
Keywords: bitbake, core-image-base, Docker, Linux, meta-virtualization, OpenEmbedded, Poky, RaspberryPi5, SSH, systemd, virtualization, WordPress, Yocto

Setting Up Docker on Raspberry Pi 5 with Yocto Project: A Step-by-Step Guide with WordPress Demo

Welcome to the third tutorial in our series about using the Yocto Project and OpenEmbedded on Raspberry Pi 5! In the first episode, we covered how to build the core-image-base. In the second, we focused on enabling SSH. Now, in this third installment, we will dive into containerization by setting up Docker on Raspberry Pi 5 using the meta-virtualization layer. This guide will help you run containerized applications like WordPress, transforming your Raspberry Pi into a powerful development platform.

What Is the Meta-Virtualization Layer?

The meta-virtualization layer simplifies the process of integrating containerization technologies, such as Docker, into Yocto-based distributions. It provides recipes and configurations for:

  • Container runtimes (like Docker)
  • Management tools
  • Necessary dependencies to efficiently run containerized applications

This layer depends on several sub-layers from meta-openembedded:

  • meta-oe
  • meta-python
  • meta-filesystems
  • meta-networking

By combining these sub-layers, developers gain all the tools needed to build and manage Docker images, even on resource-constrained devices like the Raspberry Pi 5.

Step-by-Step Guide to Set Up Docker on Raspberry Pi 5

This guide assumes you already have the Yocto Project set up. If you are starting from scratch, check out the first two tutorials in this series for detailed instructions.

1. Download Meta-Virtualization

First, clone the meta-virtualization layer from its repository:

git clone -b scarthgap git://git.yoctoproject.org/meta-virtualization

2. Download Meta-OpenEmbedded

Next, clone the meta-openembedded repository, which includes essential sub-layers for our setup:

git clone -b scarthgap git://git.openembedded.org/meta-openembedded

3. Initialize the Build Environment

Prepare your Yocto build environment:

source oe-init-build-env

4. Add Layers to bblayers.conf

Edit your bblayers.conf file to include the required layers:

bitbake-layers add-layer ../meta-openembedded/meta-oe
bitbake-layers add-layer ../meta-openembedded/meta-python
bitbake-layers add-layer ../meta-openembedded/meta-networking
bitbake-layers add-layer ../meta-openembedded/meta-filesystems

5. Enable Virtualization and Add Docker

Modify your conf/local.conf file by appending the following lines:

DISTRO_FEATURES:append = ? virtualization?
IMAGE_INSTALL:append = ? docker-moby?

6. Build the Image

Now, build the image with Docker included:

bitbake core-image-base

7. Flash the Image and Boot on Raspberry Pi 5

Once the build is complete, flash the core-image-base onto a microSD card. Boot your Raspberry Pi 5 with this image as demonstrated in the accompanying video.

Running Docker on Raspberry Pi 5

With your system up and running, you are now ready to test Docker!

1. Run the Hello-World Container

To verify Docker is working, pull and run the hello-world container:

docker run -it hello-world

2. Run the WordPress Docker Image

Let us take it a step further by running a WordPress container and exposing port 80:

docker run -it --expose 80 -p 80:80 wordpress

Conclusion

Congratulations! You have successfully set up Docker on your Raspberry Pi 5 using the Yocto Project. By leveraging the meta-virtualization layer, you can now run containerized applications like WordPress and beyond on this resource-constrained device. Stay tuned for more tutorials in this series, where we will continue to explore the possibilities of the Yocto Project and OpenEmbedded on embedded platforms!



  Home | About | Contact | Disclaimer | Sitemap © 2009-2022 Leon Anavi. All rights reserved.