Docker build issue

I tried to build an image with openjdk:17 base image with git installed and maven:3.5.0 but it is failing to build the image and throwing error, shared the error message below. Can anyone help me to solve this issue?

[2/6] RUN apt-get -y update && apt-get install -y git && rm -rf /var/lib/apt/lists/*:
0.202 /bin/sh: apt-get: command not found


Dockerfile:6

5 |
6 | >>> RUN apt-get -y update &&
7 | >>> apt-get install -y git &&
8 | >>> rm -rf /var/lib/apt/lists/*

9
ERROR: failed to solve: process “/bin/sh -c apt-get -y update && apt-get install -y git && rm -rf /var/lib/apt/lists/*” did not complete successfully: exit code: 127

Can you share why you think apt-get should exist in the base image?

Furthermore, can you share how you identified that the base image actually is based on debian/ubuntu?

I used openjdk:17 so I thought it is Debian based image and I used ‘apt-get’

but when I run the openjdk17 image I found it is based on Oracle Linux Server

docker run -it openjdk:17 bash
bash-4.4# cat /etc/os-release
NAME=“Oracle Linux Server”
VERSION=“8.5”
ID=“ol”
ID_LIKE=“fedora”
VARIANT=“Server”
VARIANT_ID=“server”
VERSION_ID=“8.5”
PLATFORM_ID=“platform:el8”
PRETTY_NAME=“Oracle Linux Server 8.5”
ANSI_COLOR=“0;31”
CPE_NAME=“cpe:/o:oracle:linux:8:5:server”
HOME_URL=“https://linux.oracle.com/
BUG_REPORT_URL=“https://bugzilla.oracle.com/

ORACLE_BUGZILLA_PRODUCT=“Oracle Linux 8”
ORACLE_BUGZILLA_PRODUCT_VERSION=8.5
ORACLE_SUPPORT_PRODUCT=“Oracle Linux”
ORACLE_SUPPORT_PRODUCT_VERSION=8.5

Can you help me to install git in this image?
I tried ‘apt-get’, ‘apk’ and ‘yum’ but none of these worked

The image is based on Oracle Linux. It uses yum or dnf.

dnf install git -y

But you should use a different image. This image is officially deprecated.

Take a look at the deprecation notices under
https://hub.docker.com/_/openjdk

And note the vulnerabilities under
https://hub.docker.com/layers/library/openjdk/17-jdk-oracle/images/sha256-98f0304b3a3b7c12ce641177a99d1f3be56f532473a528fda38d53d519cafb13

Thank you for your response now I used openjdk:11 and it is working fine

All openjdk builds are deprecated see:

Now with projects like Eclipse Adoptium which produce Eclipse Temurin builds on a wider variety of platforms which are JCK tested there is a natural replacement for a vendor neutral OpenJDK build for the JDK 8 and JDK 11 code streams for the community to use.

Upstream binaries were built by Red Hat on their infrastructure and distributed by AdoptOpenJDK on behalf of the OpenJDK jdk8u and jdk11u community projects. The last releases produced by this method were 8u342 and 11.0.16 (July 2022 CPU update). This service is now provided by the Adoptium project, and users of upstream builds should now migrate to the equivalent Eclipse Temurin releases.

1 Like