I’m trying to create an image from scratch but having difficulty with it. I searched around and didn’t really find a Dockerfile that I can use as an example.
I wanna use alpine as a base image and install openjdk17 on it. Here’s my Dockerfile
Is it safe to assume that you copied the content of openjdk:17-jdk-alpine and made minor modifications to use a newer alpine base image?
You might want to simply the command block in the RUN instruction. The check for the architecture seems overly complicated. Also it won’t hurt to run those command in linux sh shell (to be complient with default alpine shell) and see which part causes the problem.
update: fixed broken link to the image layer details.
Hi Thank you for the response.
I did not copy the content from [openjdk:17-jdk-alpine3.14], reason being is that I wanted to do everything from scratch and learn this way.
I am new to this and I have used images from docker but now I want to set everything up from scratch like I would do if I was setting up java in my own machine, which is why I decided to take this approach.
I did as you advised and I seem to have found an issue when it comes to running java
it seems like, despite having the jdk, it doesn’t find the java file
I get this when I type java or java -version
usr/java/jdk-17/bin # ls -ltra
total 456
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 serialver
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 rmiregistry
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 keytool
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 jstatd
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jstat
-rwxr-xr-x 1 10668 10668 12424 Dec 7 2021 jstack
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 jshell
-rwxr-xr-x 1 10668 10668 12424 Dec 7 2021 jrunscript
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jps
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 jpackage
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jmod
-rwxr-xr-x 1 10668 10668 12416 Dec 7 2021 jmap
-rwxr-xr-x 1 10668 10668 12416 Dec 7 2021 jlink
-rwxr-xr-x 1 10668 10668 12416 Dec 7 2021 jinfo
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 jimage
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jhsdb
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jfr
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jdeps
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 jdeprscan
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jdb
-rwxr-xr-x 1 10668 10668 12456 Dec 7 2021 jconsole
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jcmd
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 javap
-rwxr-xr-x 1 10668 10668 12424 Dec 7 2021 javadoc
-rwxr-xr-x 1 10668 10668 12416 Dec 7 2021 javac
-rwxr-xr-x 1 10668 10668 12368 Dec 7 2021 java
-rwxr-xr-x 1 10668 10668 12392 Dec 7 2021 jarsigner
-rwxr-xr-x 1 10668 10668 12384 Dec 7 2021 jar
drwxr-xr-x 2 root root 4096 Jun 9 16:29 .
drwxr-xr-x 8 root root 4096 Jun 9 16:29 ..
/usr/java/jdk-17/bin # java
/bin/sh: java: not found
/usr/java/jdk-17/bin # printenv
HOSTNAME=76d13ce10b23
SHLVL=1
HOME=/root
OLDPWD=/usr/java/jdk-17
TERM=xterm
JAVA_URL=https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/usr/java/jdk-17/bin
JAVA_HOME=/usr/java/jdk-17
/usr/java/jdk-17/bin #
The downloaded java archive is not compatible with alpine out of the box, as alpine uses musl instead of glibc as its c library.
If you insist on using openjdk from Oracles website, you will need to install glibc (a short google search should yield plenty of hits on how to do that).
Or you can use openjdk from the alpine repos. An example Dockerfile would look like this:
# syntax=docker/dockerfile:1
FROM alpine:3.16.0
RUN apk add --no-cache java-cacerts openjdk17-jdk
For time beeing it will install this exact version: