Build Yocto x86_64 on ubuntu using Docker
You can follow below mentioned steps to build a Yocto image for an x86_64 using ubuntu docker. You can do the same steps on host as well, however build on docker container ensure that host setup is not disturbed.
Create a Docker Image
Create a new directory and add the following content to a file named Dockerfile
# Use a lightweight base image with common build tools
FROM ubuntu:20.04
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8
# Install required packages
RUN apt-get update && apt-get install -y \
gawk wget git-core diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat cpio python3 python3-pip \
python3-pexpect xz-utils debianutils iputils-ping lz4 zstd sudo vim \
locales && \
locale-gen en_US.UTF-8 && \
apt-get clean
# Set a working directory
WORKDIR /yocto
# Optional: Add a non-root user for builds
RUN useradd -ms /bin/bash yocto && echo "yocto:yocto" | chpasswd && adduser yocto sudo
USER yocto
# Expose a volume for build outputs
VOLUME /yocto/build
CMD ["/bin/bash"]
Build a Docker Image
docker build -t yocto-build-env .
Build Yocto Image inside docker
Create a new directory on host and git clone yocto repository
mkdir $HOME/yoctobld
cd $HOME/yoctobld
git clone git://git.yoctoproject.org/poky.git
cd poky
git checkout kirkstone # Replace with your desired branch
cd $HOME/yoctobld
docker run -it --rm --name yocto-build -v $(pwd):/yocto yocto-build-env
# now you will enter container
# change ownership to yocto to be able to build on host directories
# use password yocto for sudo command below
sudo chown -R yocto:yocto poky
sudo chown -R yocto:yocto build
cd poky
source oe-init-build-env /yocto/build
bitbake core-image-minimal
The image will be generated under /yocto/build/tmp/deploy/images on container or $HOME/yoctobld/tmp/deploy/images on HOST