Quick Tip: Installing OpenJDK in Debian container

Written by beld_pro | Published 2017/05/16
Tech Story Tags: docker | java | containers | development | programming

TLDRvia the TL;DR App

The default Debian sources doesn't include the latest OpenJDK but you can get it from jessie-backports . Here's a quick tip to install it in a container.

First of all, get debian:jessie into your Docker daemon:

docker pull debian:jessie

jessie: Pulling from library/debian

10a267c67f42: Pull complete

Digest: sha256:476959...c758245937

Status: Downloaded newer image for debian:jessie

Now run a container that uses debian:jessie and and add jessie-backports sources to our sources:

docker run -it debian:jessie /bin/bash

...

echo 'deb http://deb.debian.org/debian jessie-backports main' \> /etc/apt/sources.list.d/jessie-backports.list

That is, insert deb [http://deb](http://deb) ... to the file /etc/apt/sources.list.d/jessie-backports.list . deb indicates that the archive contains binary .deb packages and where these can be found (here you could either specify the official debian.org or another mirror). Right after the URL we specify a distribution, which can be thought of as a release to target at. Here we target jessie-backports which contains more cutting-edge releases (see https://backports.debian.org/Instructions/).

Having that done, update your package lists with apt update . What this does is essentially fetch information about the version of packages that can be fetched (it won't upgrade the packages you have installed though).

apt update -y

Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]

...

Get:3 http://deb.debian.org jessie-backports InRelease [166 kB]

...

All packages are up to date.

Now it's just a matter of targeting thejessie-backports distribution and installing openjdk8 👌

apt install --target-release jessie-backports \openjdk-8-jre-headless \ca-certificates-java \--assume-yes

Notice the use of --target-release . This allows us to target packages from jessie-backports (there's where openjdk8-jre-headless is present). With --assume-yes we are not prompted for confirmations).

And that's it! Now you have the latest OpenJDK installed 👊

java -version

openjdk version "1.8.0_131"

OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1~bpo8+1-b11)

OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Below is a Dockerfile that installs OpenJDK following what was discussed here. You can build it using docker build --tag <image_name> . (where . indicates the directory where you put the Dockerfile).

And that's it!

If you have any questions, let me know!

Follow me on Twitter if you wish to get in touch and have some updates about this kind of things ✌️ twitter.com/beld_pro .

🎩


Published by HackerNoon on 2017/05/16