Build your own Docker for Yocto Builds
One of the things you can do to create a Docker Image that you are happy with is to build one yourself.
Thanks for the Docker software, it is quite easy to do and effective.
Why build your own?
One of the main reason to do your own build is to have configuration control so you can recreate the docker on demand. This is usually a requirement for any regulated industry
The other reason is to have packages that believe you need on every docker. For e.g. I prefer to use the vi editior in the linux client, so I add that package to every docker I create.
Lets build the Dockerfile
The first step is to create a new Dockerfile that defines your Docker.
Here are the key aspects of this file:
The first line is to define what you want to base this docker on. You can build from scratch, but I prefer to piggy back on Ubuntu.
FROM ubuntu:24.04
Next we install the locales package and in my case, I set the current locale to US West Coast
Here we use the apt-get utility to install the packages. This is available by default on ubuntu.
You get the apt-get database updates and then install the package you want and then in the end remove any temp files that were created.
RUN apt-get update && apt-get install -y locales && \
locale-gen en_US.UTF-8 && \
rm -rf /var/lib/apt/lists/*
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
Now we get started on the packages that are needed for Yocto Scarthgap. You can see the list of packages here:
https://docs.yoctoproject.org/scarthgap/ref-manual/system-requirements.html#ubuntu-and-debian
In addition to the packages that Yocto details, I am also adding in vim for the vi editing tool that I like.
Again using apt-get utility :
RUN apt-get update && apt-get install -y \
build-essential \
chrpath \
cpio \
debianutils \
diffstat \
file \
gawk \
gcc \
git \
iputils-ping \
libacl1 \
lz4 \
python3 \
python3-git \
python3-jinja2 \
python3-pexpect \
python3-pip \
python3-subunit \
socat \
texinfo \
unzip \
vim \
wget \
xz-utils \
zstd \
&& rm -rf /var/lib/apt/lists/*
Now we come to the good things to do with every Docker image. Consider these are general good practices.
Create a working directory:
WORKDIR /workdir
Now lets create a new user called poky
RUN useradd -m -s /bin/bash poky && \
usermod -aG sudo poky &&echo "poky ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Give the new user called poky ownership rights to the working directory
RUN chown -R poky:poky /workdir
Set the default use to be poky when you run the container.
USER poky
I have built this docker on a Mac, so you can get a yocto builder docker that I use on my Mac from the docker hub here :
https://hub.docker.com/repository/docker/bearcreektech/yocto-scarthgap/general
See the code on GitHub
Want to see the steps and the configuration files for your use?
Build your own docker for Yocto Scarthgap
Yocto Article Series
This is the seventh article in the series. Older articles links:
2. What is the bitbake tool for Yocto?
3. How to use the poky for custom Linux dev using Yocto
4. Setup the foundation for building with Yocto
5. Build a x86 Minimal Image on a MAC using crops/poky docker
6. Build a ARM Minimal Image on a MAC using crops/poky docker