Docker build machine for Maven/Java – part 2

Slight improvement to the previous post about building using a Docker container.

I’ve split it into two parts. The first part simply creates an image with OpenJDK 1.7, Maven 3.1.1, Git, tar, unzip and vim. The second part downloads the test project and compiles it.


This means you don’t have to download the OpenJDK and associated tooling each time you want to compile something (speeding up container creation).

wget https://raw.githubusercontent.com/AndrewGorton/DockerJavaMavenBuildBox/v1.0.1/build-base.sh
chmod u+x build-base.sh
 
wget https://raw.githubusercontent.com/AndrewGorton/DockerJavaMavenBuildBox/v1.0.1/build-builder.sh
chmod u+x build-builder.sh
 
./build-base.sh
./build-builder.sh
 
docker run -i -t -p 49000:8080 -p 49001:8081 devsoup/simple-builder java -jar /var/tmpbuild/SimpleDropWizardEcho-develop/target/SimpleDropWizardEcho-1.0.1.jar server

wget https://raw.githubusercontent.com/AndrewGorton/DockerJavaMavenBuildBox/v1.0.1/build-builder.sh
chmod u+x build-builder.sh

./build-base.sh
./build-builder.sh

docker run -i -t -p 49000:8080 -p 49001:8081 devsoup/simple-builder java -jar /var/tmpbuild/SimpleDropWizardEcho-develop/target/SimpleDropWizardEcho-1.0.1.jar server

You should be able to go to http://localhost:49000/echo?echo=hello+world to see the simple DropWizard echo service running (the admin URLs run on port 49001).

As I run on a Mac, I had to figure out the port forwarding to make this work. The ports have to go from your Mac, to the docker-vm, then onwards to the docker container. So if you set up the standard port forwarding as per the setup instructions on the docker.io website, then you are binding ports 49000-49900 on the Mac to the same ports in the docker-vm. You can then use these ports to map to your docker container (eg docker ... -p 49000:8080 ...).

This is my personal blog - all views are my own.

Tagged with: , , , , , ,