Quick Tip: Installing OpenJDK in Debian container
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:jessiejessie: Pulling from library/debian10a267c67f42: Pull completeDigest: sha256:476959...c758245937Status: 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 ... 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 -yGet: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-yesNotice 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).
Get beld 🎩’s stories in your inbox
Join Medium for free to get updates from this writer.
And that's it! Now you have the latest OpenJDK installed 👊
java -versionopenjdk 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 .
🎩
Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!










