How it works...

In the first step, we install Docker—a virtualization environment that allows an isolated Linux operating system to run on Windows, macOS, or Linux. This is a convenient way of distributing and deploying containers that uniformly encapsulate all of the libraries and programs required for any operating system you use.

After installing Docker, run a quick command to check whether it has been installed correctly:

After checking the installation, we need to fetch the ready-made Ubuntu image from the Docker repository. Docker images have tags; we can use the bionic tag to find Ubuntu version 18.04:

It takes time for the image to download. Once the image is fetched, we can create a directory, which we will use for development. The directory content will be shared between your operating system and Linux, running in Docker. This way, you can use your favorite text editor to work on code but still use the Linux build tools to compile the code into the binary executable files.

Then, we can start a Docker container using the Ubuntu image fetched in step 4. The option -v $HOME/test:/mnt command line makes the folder created in step 5 visible to Ubuntu as the /mnt directory. This means that all of the files you create in the ~/test directory automatically appear in /mnt. The -ti option makes the container interactive, giving you access to the Linux shell environment (bash):

Finally, we run a quick sanity check of the . uname container, which displays information about the Linux kernel, as shown here:

Although the exact version of your kernel may differ, we can see that we are running Linux and our architecture is x86. This means we have set up our build environment, where we will be able to compile our code in a unified way, whatever operating system is running on our computer. However, we are still not able to run the compiled code because our target architecture is Acorn RISC Machines (ARM), not x86. We will learn how to set up an emulated ARM environment in the next recipe.