Dockerizing Your CPP Projects

February 18, 2024

In this post, I will share how to create a docker environment for C++ projects targeted for Ubuntu.

It works on my machine but fails on CI!

C++ does not provide an default package manager like Cargo in Rust, pip in python, or npm in JavaScript, etc. Third party libraries are added using a mix of techniques such as installing from Linux distro’s repositories (apt-get), or git submodules, or half-baked solutions like Conan. Unfortunately they all have disadvantages:

Docker

My preferred solution to the above problems is to create a Docker image and work on the project inside a container based on the image. The following are some advantages of this workflow.

I use Docker Compose for multi-container orchestration, i.e., a container for the robotics stack and another container for the simulation environment. The following is an example of a client container sending a list of integers to the server, the server returns the sum of the integer, the client then stores the sum to a file on the host machine.

code



← Back