Using Docker to work with an old jdk

Ever tried to work on an old project that requires that you install on old version of java. Say java 5. On a Mac… You know this nightmare that no windows user will ever face:

You want me to install an old jdk on my mac? Are you crazy? That’s so complicated.

An easy way to do that is to boot a linux/windows vm. An easier way is to use Docker.

Here’s the Dockerfile that creates a container with java6 inside. You can then use the container to build a maven project.

FROM ubuntu:12.04
MAINTAINER David Gageot

# Install java 6
RUN apt-get update
RUN apt-get install -y openjdk-6-jdk

# Install tools
RUN apt-get install -y maven

# Define mountable directories.
VOLUME ["/dir"]

# Define working directory.
WORKDIR /dir

# Define default command.
CMD ["java"]

Build the container with docker build -t dgageot/java6 .
Run the container with docker run -t dgageot/java6 java or docker run -t dgageot/java6 mvn

You can map a folder on your host to the /dir folder on docker so that the java inside the container is used to build the project outside the container.

Have fun!

2 thoughts on “Using Docker to work with an old jdk”

  1. Unfortunately, “it doesn’t work on my machine”© (on a mac)
    Because boot2docker is not yet handling this case easily for us (with boot2docker, we must go one step further : sharing host boot2docker virtualbox vm, then boot2docker virtualbox vm shared folder your docker image

    Didn’t achieved the first step at the moment (the second one would be easy, as described in this post)

    1. Yes. There’s work in progress on boot2docker side to be able to map a host folder, the host being your mac, not boot2docker’s vm. In the meantime, you can scp files to boot2docker’s vm

Comments are closed.