How to Cross Compile Go Programs using Docker
There are several ways to cross compile Go programs, but the way we’re going to show you is awesome because you don’t have to install any libs or anything. That said, you do need Docker installed, but you already have that anyways, right?
We use this to create our Iron.io command line tool binaries. You can find our tool and build scripts here: https://github.com/iron-io/ironcli
First off, be sure you’ve vendored your dependencies. There are various ways to do this, but if you’re using godep, use godep save -r to rewrite imports so it doesn’t need any special GOPATH changes. As suggested in the Docker for Development post, vendor everything! It’s the best way to roll.
Now just run the following magical command after modifying the path and binary name:
Boom! After this runs you’ll have 6 binaries, two for each architecture (32 bit and 64 bit) for each operating system (Linux, Mac and Windows). If you want it built for other OS’s and ARCH’s, you can find the full list here.
Leave a Comment