Docker Build Environment: Difference between revisions

From Variscite Wiki
Line 18: Line 18:
https://docker-curriculum.com/<br>
https://docker-curriculum.com/<br>
<br>
<br>
This guide describes how to use Docker as a Host build environment for building Variscite Yocto, Debian, Android, B2Qt images.
This guide describes how to use Docker as a Host build environment for building Variscite Yocto, Debian, Android and Boot2Qt images.
<br><br>
<br><br>
If you are interested in running Docker containers on top of Yocto, please see our Docker Guide: https://variwiki.com/index.php?title=Docker_Guide&release={{#var:RELEASE_PARAM}}
If you are interested in running Docker containers on top of Yocto, please see our Docker Guide: https://variwiki.com/index.php?title=Docker_Guide&release={{#var:RELEASE_PARAM}}

Revision as of 14:16, 19 April 2021

DART-MX8M-MINI - Docker

Docker Introduction

Docker is a software platform that allows the creation, testing and distribution of applications via containers.
Containers let you run your applications in resource-isolated processes. There are some similarities to virtual machines, but containers are more portable, more resource-friendly, and enables faster software delivery cycles.
Often used with docker there's a companion tool known as docker-compose: compose is used for defining and running multi-container Docker applications.

You can check Docker online documentation at:
https://docs.docker.com/get-started/
https://docs.docker.com/compose/
https://training.play-with-docker.com/
https://docker-curriculum.com/

This guide describes how to use Docker as a Host build environment for building Variscite Yocto, Debian, Android and Boot2Qt images.

If you are interested in running Docker containers on top of Yocto, please see our Docker Guide: https://variwiki.com/index.php?title=Docker_Guide&release=RELEASE_DUNFELL_V1.4_DART-MX8M-MINI

Why Build using Docker?

Each version of Yocto, Debian, Android, etc. has unique Host requirements (e.g. Ubuntu 16, Ubuntu 18...). This can be cumbersome during development if you are working on legacy projects and new projects at the same time. Over time, we've all come up with our own solutions to this problem by using Virtual Machines or even keeping old computers just to build an occasional image.

Docker is a great solution to this problem and provides:

  • A GIT revision controlled build environment
  • Can run on any OS and Hardware that supports the Docker Runtime
  • Does not require strict allocation of RAM and hard drive memory
  • Has very little CPU/IO overhead, does not impact build time
  • Containers start and stop in 1-2 seconds


Docker's efficiency allows multiple containers to be run simultaneously without burdening the host OS.

Setting Up Host Computer

Host Hardware

For building Linux / Android images, it is recommended to have a dedicated build computer. In 2021, it is very affordable to build a recommended machine with a 16c/32t CPU, 64GiB of memory, and a 2TB SSD. Compile time is generally reduced linearly with the number of CPUs.

Host OS

Install the latest LTS version of Ubuntu: https://ubuntu.com/download

After a fresh installation, install Docker

 sudo apt update && sudo apt install docker.io

Give permissions to run Docker without sudo

 sudo usermod -aG docker ${USER}

Install Linux Headers (required for some Yocto versions)

 sudo apt install linux-headers-$(uname -r)

Logout and login again for permissions to take effect

Using Variscite's Docker Container

Clone Variscite's Docker container repository

 $ git clone https://github.com/varigit/var-host-docker-containers.git ~/var-host-docker-containers

Start your first Docker container. The first time you start the container, it will take some time to build the container.

After the container finishes building, it will enter the docker container with an interactive shell in the current working directory.

Start Ubuntu 16.04 Container:

 $ cd ~/var-host-docker-containers
 $ ./run.sh -u 16.04
 vari@908b2ecb107c:/workdir$ grep DESCRIPTION /etc/lsb-release
 DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"

Start Ubuntu 18.04 Container:

 $ cd ~/var-host-docker-containers
 $ ./run.sh -u 18.04
 vari@4822cf0e987c:/workdir$ grep DESCRIPTION /etc/lsb-release
 DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"

Start Ubuntu 20.04 Container:

 $ cd ~/var-host-docker-containers
 $ ./run.sh -u 20.04
 vari@abe078d0f67c:/workdir$ grep DESCRIPTION /etc/lsb-release
 DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"

See run options:

 $ cd ~/var-host-docker-containers
 $ ./run.sh -h

Building an Image

This example shows how to build a Yocto Dunfell image using Docker. In general, the process is the same for all target Operating Systems. Please follow Variscite's build guide and host requirements for your specific releases

Make a working directory from your Host OS:

 $ mkdir ~/docker-yocto-build

Start a Ubuntu 20.04 Docker container:

 $ cd ~/var-host-docker-containers
 $ ./run.sh -p -u 20.04 -w ~/docker-yocto-build

Note: -p option starts Docker in privileged mode, which allows access to Host devices and is necessary for Debian

vari@abe078d0f67c:/workdir$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b refs/tags/dunfell-fslc-5.4-2.1.x-mx8mm-v1.4 -m default.xml
vari@abe078d0f67c:/workdir$ repo sync -j4
vari@abe078d0f67c:/workdir$ MACHINE=imx8mm-var-dart DISTRO=fslc-xwayland . setup-environment build_xwayland
vari@abe078d0f67c:/workdir$ source setup-environment build_xwayland
vari@abe078d0f67c:/workdir$ bitbake fsl-image-gui

The output images can be accessed from your host computer:

$ ls -l ~/docker-yocto-build/build_xwayland/tmp/deploy/images/imx8mm-var-dart/