Boost C++ Library Docker Container
Introduction
Boost is a famous open-source portable C++ library that follows the conventions of C++ STL and is compatible with the C++ Standard Library. Because the standard of Boost library is close to the C++ Standard Library, it has been one of the most valuable sources for additions to the Standard C++ Library.
Because Boost is so portable, we would like to run it inside a Docker container almost anywhere. In this blog post, I would like to quickly show how to build Boost C++ library Docker containers.
Boost Docker Container
We will build Boost C++ library Docker containers for both the x86-64 and aarch64 platforms for any Boost C++ library version specified. The Dockerfile and the Boost-CMake C++ examples are available on GitHub.
Set Boost Library Version
In this case, we will build Boost C++ library 1.84.0.
1 | $ BOOST_VERSION=1.84.0 |
Build Docker Image
The following Boost Dockerfile allows us to build a container that has both Boost and CMake installed.
1 | FROM ubuntu:24.04 |
To build the Boost Docker image locally, please run the following command.
1 | $ docker build -f docker/boost.Dockerfile --build-arg BOOST_VERSION=${BOOST_VERSION} --tag boost:${BOOST_VERSION} . |
Build Docker Image Cross Platform
To build the Boost Docker images for both x86-64 and aarch64, please run the following command. The Boost Docker images will also be pushed to Docker Hub.
1 | $ sudo apt-get install -y binfmt-support qemu-user-static |
Pull Docker Container
Instead of building the Boost Docker images locally, we could also pull the Boost Docker images that we just built from Docker Hub.
1 | $ docker pull leimao/boost:${BOOST_VERSION} |
Run Docker Container
To build the Boost Docker container, please run the following command.
1 | $ docker run -it --rm -v $(pwd):/mnt -w /mnt boost:${BOOST_VERSION} |
Boost Examples
To show that the Boost library we just built works inside the Docker container, we will build and run two Boost C++ examples. One build with a Boost header-only library and the other one links to a Boost shared library dynamically.
Build Examples
To build the Boost examples using CMake, please run the following command.
1 | $ cmake -B build |
Run Examples
Header-Only Example
The header-only example uses the Boost.Lambda library and will triple the input integer values.
1 | $ echo 1 2 3 | build/header-only/Triple |
Library-Link Example
The library-link example uses the Boost.Regex library and will extract the subject from a piece of Email text.
1 | $ build/library-link/SubjectExtraction < library-link/data/jayne.txt |
References
Boost C++ Library Docker Container