paint-brush
Quick Tip: Installing OpenJDK in Debian containerby@beld_pro
10,407 reads
10,407 reads

Quick Tip: Installing OpenJDK in Debian container

by beldMay 16th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The default Debian sources doesn't include the latest OpenJDK but you can get it from <code class="markup--code markup--p-code">jessie-backports</code>&nbsp;. Here's a quick tip to install it in a container.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Quick Tip: Installing OpenJDK in Debian container
beld HackerNoon profile picture

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 .

🎩