hariszaf
hariszaf

Reputation: 61

How to add Java 11 on Dockerfile?

I am trying to make a Dockerfile where Java11 has to be "loaded".

However, when I try:

RUN add-apt-repository -y ppa:linuxuprising/java 

then I get this error:

/bin/sh: 1: add-apt-repository: not found The command '/bin/sh -c add-apt-repository -y ppa:linuxuprising/java' returned a non-zero code: 127

My question is how could I "install" Java11 on Docker?

Upvotes: 5

Views: 51192

Answers (3)

Gonzalo Matheu
Gonzalo Matheu

Reputation: 10064

Assuming that is not possible to base your image on a OpenJDK official image.

Take a look to how it is installed in the official image Dockerfile (or the repository).

There are also alternatives images, like AdoptOpenJDK (Dockerfile based on Ubuntu)

Upvotes: 9

Jochen Haßfurter
Jochen Haßfurter

Reputation: 915

For CentOS in your docker image you still can use:

FROM centos
RUN yum install -y java-11

Upvotes: 7

Werner Raath
Werner Raath

Reputation: 1492

Your specific error you were receiving is because software-properties-common is not installed.

So make sure you do the following before add-apt-repository -y ppa:linuxuprising/java:

RUN apt-get update \
    && apt-get install -y software-properties-common

Upvotes: 4

Related Questions