Creating a Cross Platform Build Environment in Docker

Dan Bryant
tsMuxer Development Blog
2 min readNov 28, 2019

When I started out trying to get things working with tsMuxer one of the things I really wanted to do was to eventually use Docker for creating the executables. Docker is a fantastic technology for creating small operating system images that can be used for very specific tasks.

I used a virtual machine in the early days to do all the build testing. I still use one day-to-day. However to build for each platform (Windows, Linux and MacOS) with virtual machines would traditionally mean that we have to have 3 virtual machines — each with their own build environment. Thankfully we can actually streamline this by setting up cross compilation environments for each of our chosen platforms. So by using a Linux VM and installing MXE and osxcross we can actually create builds for Linux, Windows and MacOS all from the same host.

The beauty of this is that we can create one host with one setup and use it to create executables for 3 different target systems. I would recommend trying it out in a VM first, noting all the steps you took to get the system set up fully. Once you have done it in a VM next you can just replicate the exact same setup in Docker. That’s exactly what I did, creating the Dockerfile and publishing it to GitHub.

Originally I used existing Docker containers with MXE and osxcross and tried to modify the containers for my needs. It didn’t work. You are much better off crafting a container for your specific purpose. Although I used Ubuntu as my base (to match my VM) you could use something more streamlined like Arch (Anarchy Linux would be a decent recommendation for the VM, vanilla Arch for the container).

The beauty of using a Docker container rather than a VM is it is so much faster, streamlined and easier to integrate into other tools. We may even cover that in a further blog post :)

Once you have tested your Dockerfile locally and uploaded it to GitHub you can link your GitHub repository directly to Docker Hub. Then on each push to your Git repo a new Docker container will be published to Docker Hub.

Finally you can include some instructions for the users to use — or use it in an automated workflow. But more on that next time!

--

--