Automating Docker Builds With Gradle
We’re all using Docker containers these days to do all sorts of great stuff, but it’s not always obvious how best to automate the building of images and embed good repeatable processes into our projects. In this article you’ll discover one of the best approaches I’ve found to automate Docker in your project. It is to create tasks for the building of images and running of containers within your Gradle project.
With this approach, anyone checking out your code can immediately start a Docker container without having to read your documentation. If you’re working on a project with multiple source code repositories, having a consistent approach like this makes it a lot easier for people to get to grips with code you’ve written.
When it comes to Docker plugins there are two main players right now, the Palantir Docker Plugin and the Bmuschko Docker Plugin. Technically, they are best described as suites of plugins as there are separate plugins providing specific fine grained functionality.
Palantir Docker Plugin : https://plugins.gradle.org/search?term=com.palantir.docker Bmuschko Docker Plugin: https://plugins.gradle.org/search?term=com.bmuschko.docker
I generally use the Palantir Docker Plugin as it’s slightly less opinionated in that it let’s you configure your own Dockerfile. This is the plugin I’ll be using in this article. The Bmuschko Docker Plugin, on the other hand, generates the Dockerfile for you or allows you to configure it’s instructions in your build.gradle.
They are both good plugins, so here’s a quick summary of what to expect from each.