Develop bindings easily with Docker

Avoid installing dependencies on your machine

Francesc Campoy
Google Cloud - Community
3 min readAug 1, 2015

--

Imagine the situation: you want to write binding of FFmpeg for your favorite language, and of course you want to use your laptop to do so.

These are the steps:

  1. install FFmpeg on your computer

Wait, what do you say? You don’t install stuff? The only thing that runs on your laptop is docker containers?? Jessie, is that you?

Ok, let me try again:

  1. create a Docker image with FFmpeg in it.
  2. add to it your dev tools, your code, your dot files, and …

Ok, you don’t need to roll your eyes so hard, I get it!
So you want to basically edit your code on your laptop … but compile it from the container? Is that even possible?

Well, yes it is!

My development process

Spoiler alert: my solution to this is quite simple but I was so pleased with how it works that I decided to share it. Finally, for this example I will use Go as my programming language (after all, I’m a gopher) but you could do something similar with any language you like.

First I wrote a Dockerfile based on official golang Docker image that installs FFmpeg.

Great, let’s build it and run it!

Yes! We have now a bash running in a container where both go and FFmpeg are installed!

But where is our code? We could add a line in our Dockerfile to add all the code we need, but then we should rebuild the container every time we change the code. Can we make this better?

Docker volumes FTW

This is where the cool stuff happens. We can add our code when we run our container rather than when we build it using Docker volumes.

Now if we do changes on any of the files in the mapped directory from your host the container will see the changes immediately and vice versa. So we can use our favorite editor from our laptop and run any tools that need the dependencies from the container.

You can use your tools to edit your code as you like, and your dependencies stay in the container (green) where you can run go install.

And the best part is that this will help people contribute to your project! No need to explain how to install all the different dependencies your project might have, just add the Dockerfile to your repo!

Thanks for reading and please let me know your questions or comments either commenting here or at @francesc.

--

--