Well, have I got some news for you. If you’ve been following my latest blog posts, I’ve been talking a good deal about Docker, the amazing containerization platform making it easier than ever to develop and deploy web applications. The first post covered the Docker basics and the Docker CLI. The second, introduced Docker Compose, Docker’s more sophisticated, easier (in my opinion) to use, multi-service option.

Docker is a very powerful tool when used correctly, but it takes a minute to get your head around:

the commands,

the file structure,

the whole containerization concept, itself.

It’s not easy if you’ve not used it before, there’s a definite learning curve. But Google, ever the leader in technology, has just released a game changer…

Meet Jib

Jib, is a brand new, just released, Google Container Tools-based, Java plugin that will containerize your application.

Put simply:

Jib builds Docker and OCI images for your Java applications and is available as plugins for Maven and Gradle. — Jib, Github

What this means for us is:

no Dockerfile setup,

setup, no customized scripting for Maven or Gradle,

out of the box Docker image generation and publication.

Basically, no Docker complexity, but all of the Docker benefits.

How? A plugin, a very simple plugin in your project. I’ll show you just how simple below.

Implementing Jib in Gradle

There are both Maven and Gradle plugins for Jib. I’ll be using Gradle because that’s what I’m most familiar with.

We begin with the build.gradle file. First and foremost, make sure you’re working with Gradle 4.6 or later — this is required for Jib.

Next, the changes to the file. Inside of the build.gradle , in your plugins section, add this line.

Yes, it really is that easy to generate a Docker image now.

And that’s it. You’re done with the changes needed in your Java application.

Now, from the command line run the Gradle task ./gradlew jibDockerBuild . This will generate your local Docker image and give you its image name and version.

Ok, final step, the Docker run command in the terminal: docker run -p <host port: Docker app port> <image name: version> . And with this your application should start up.

I made a sample Java application and stored it in Github here, so you can see just how simple this really is.

I also left the Dockerfile in there, so you can see what used to be necessary to run Docker. Keep in mind, this project is only set up for building and running local images, if you want to push to Docker hub, see the Jib official documentation (and check back, I may do a follow up post on it).

For my project, you’d run the same ./gradlew jibDockerBuild , then this Docker run command: docker run -p 8080:8080 java-example:1.0.0-SNAPSHOT .

This is what you’ll see when you go to http://localhost:8080 in your browser.