2018-03-27 [Technical,Short] run git and Gradle and Java from docker without installing anything

Docker is not a light-VM it is much more

Docker is often used as a light-VM. But this is the wrong way to see it. For me, it really shines when you use it to run complex programs, with complex dependencies without installing anything on your computer.

As a developer I often need to have multiple versions of the same software. For example, as a java dev, I might have Java-8, Java-9 and now Java-10 on the same machine. Testing my code on all three requires lots of effort and is prone to errors (My code might be compiled with the right version but run with the wrong one).

With Docker I can simplify this by having 3 images and compiling, running and testing my code in containers.

How to use containerised version of git and Gradle

For the sake of simplicity, because Java is always complex, and I an lazy, I’ll show an example of how to use containers to run git and Gradle in a protected environment.

Here I use a docker image to run git and another one to run Gradle, without installing git or Gradle on my computer, without installing dependencies manually and without risking to have the different software working together in unplanned ways.

alias dgit="docker run -ti --rm -v $(pwd):/git alpine/git”

dgit clone https://github.com/fcontrepois/Fbot.git
cd Fbot
# Everytime you change directory you need to re-run the alias as $(pwd) needs to be updated to the new directory
alias dgit="docker run -ti --rm -v $(pwd):/git alpine/git”
# next lines values changed for security reasons :)
dgit config user.email "frank@frankcontrepois.com"
dgit config user.name "frankcontrepois"
dgit commit -m "First commit from start.spring.io”

alias dgradle="docker run --rm -v "$PWD":/code -v /Users/frank/dev/gradle-home-docker:/gradle_home -w /code gradle gradle-g /gradle_home"
dgradle build

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.