I am trying to configure Alpine with Oracle JDK. I have downloaded the JDK and am copying it into my image and using it there.
When I run which java it reports back the correct path /jdk-11.0.10/bin/java but when I try to run any java command it says it is not found.
I tried to reference some info from
https://wiki.alpinelinux.org/wiki/Installing_Oracle_Java
WRT how to do this but I'm not having any luck.
Any input would be appreciated!
FROM alpine
RUN apk add freetype fontconfig paxctl
COPY jdk-11.0.10_linux-x64_bin.tar.gz /
RUN tar -xf jdk-11.0.10_linux-x64_bin.tar.gz
ENV JAVA_HOME /jdk-11.0.10
ENV PATH ${JAVA_HOME}/bin:${PATH}
CMD echo ${PATH}
CMD echo which java
RUN paxctl -c java
RUN paxctl -m java
RUN paxctl -c javac
RUN paxctl -m javac
CMD java -version
Related
I have Java app and want to generate docker image, I have shell script like this:
#!/bin/sh
java -version
export APPLICATION_DIR=$PWD
for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`
do
export CLASSPATH=$rJarFile:$CLASSPATH
done
export CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
java -Xverify:none -Xmx2048m -Djava.awt.headless=true -DFI_IS_CONFIGSER=N -DFICLIENT_APP_PATH=${APPLICATION_DIR} -DFI_APP_NAME=FIONLINE -DFI_BASE_INSTANCE_ID=1 -DPRODUCT_BOOTSTRAP_FILE=${APPLICATION_DIR}/data/BootstrapFile.properties -DFEBA_SYS_PATH=${APPLICATION_DIR}/data
And I try to convert it into Dockerfile like this
# FROM openjdk:8
FROM openjdk:11
RUN javac -version
# Create app directory
WORKDIR /usr/src/app
# Bundle app source
COPY . .
ENV APPLICATION_DIR=/usr/src/app
RUN echo $APPLICATION_DIR
RUN for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`; do export CLASSPATH=$rJarFile:$CLASSPATH; done
RUN echo $CLASSPATH
ENV $CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
# Run app
ENTRYPOINT ["java", "-Xverify:none", "-Xmx2048m", "-Djava.awt.headless=true", "-DFI_IS_CONFIGSER=N", "-DFICLIENT_APP_PATH=${APPLICATION_DIR} -DFI_APP_NAME=FIONLINE -DFI_BASE_INSTANCE_ID=1", "-DPRODUCT_BOOTSTRAP_FILE=${APPLICATION_DIR}/data/BootstrapFile.properties", "-DFEBA_SYS_PATH=${APPLICATION_DIR}/data"]
It can be generated, but there's an error when I try to run it like this:
Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: setenv: invalid argument: unknown
I've also changed this script RUN for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`; do export into this RUN for rJarFile in ls ${APPLICATION_DIR}/lib/*.jar; do export CLASSPATH=$rJarFile:$CLASSPATH; done, but none of them working. I don't want to make Dockerfile execute the script. Below is logs when i generate and run it.
You cannot update the classpath as you do with:
ENV $CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
instead you can do
ENV CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
Also - please consider moving the script into a separate shell script and adding into the container. This would greatly simplify the Dockerfile, for example:
# FROM openjdk:8
FROM openjdk:11
RUN javac -version
# Create app directory
WORKDIR /usr/src/app
# Bundle app source
COPY . .
ENV APPLICATION_DIR=/usr/src/app
RUN echo $APPLICATION_DIR
ENTRYPOINT ["/usr/src/app/start_java.sh"]
and keep your existing script inside start_java.sh
I have tried multiple releases from here using :
sudo -i
cd /usr/lib/jvm
wget [release link here]
tar xzf [file name here]
export PATH=$PWD/[dir here]/bin:$PATH
java -version
But after java -version I always get:
/usr/lib/jvm/[dir here]/bin/java: cannot execute binary file: Exec format error
Which means I have chosen the wrong release/architecture. Is there a release that works with Raspberry Pi's or is there another way to install Java 16?
Answering my own question.
cd [minecraft directory here]
wget https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk16u-2021-05-08-12-45/OpenJDK16U-jdk_arm_linux_hotspot_2021-05-08-12-45.tar.gz
tar xzf OpenJDK16U-jdk_arm_linux_hotspot_2021-05-08-12-45.tar.gz
export PATH=$PWD/jdk-16.0.1+4/bin:$PATH
java -version
You might have to do
export PATH=$PWD/jdk-16.0.1+4/bin:$PATH
after a reboot
I am trying to integrate SonarQube into my CI process. I tried to install SonarScanner in Docker, but it appears it cannot find java tho it can be run
Dockerfile
# Docker, AWS CLI, Terraform, NodeJS
FROM docker:18-dind
RUN echo "1"
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk update
RUN apk add awscli nodejs nodejs-npm wget unzip jq openjdk11
RUN wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip
RUN unzip terraform_0.11.13_linux_amd64.zip
RUN mv terraform /usr/local/bin
RUN npm i -g sequelize sequelize-cli mysql2
RUN wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.2.0.1873.zip
RUN unzip sonar-scanner-cli-4.2.0.1873.zip
RUN ls sonar-scanner-4.2.0.1873
ENV PATH="/sonar-scanner-4.2.0.1873/bin:${PATH}"
RUN which java
ENV JAVA_HOME=/usr/bin
RUN echo $PATH
RUN java --version
RUN ls /sonar-scanner-4.2.0.1873/bin
RUN sonar-scanner --help
The logs
Step 15/20 : RUN which java
---> Running in 96b487f5b44f
/usr/bin/java
Removing intermediate container 96b487f5b44f
---> 5026de427a57
Step 16/20 : ENV JAVA_HOME=/usr/bin
---> Running in 4d7eee221e41
Removing intermediate container 4d7eee221e41
---> 76b9a8b9d803
Step 17/20 : RUN echo $PATH
---> Running in 4278142f7153
/sonar-scanner-4.2.0.1873/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 4278142f7153
---> c3d528bdaa7e
Step 18/20 : RUN java --version
---> Running in 7df7e2d8a441
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-alpine-r0)
OpenJDK 64-Bit Server VM (build 11.0.5+10-alpine-r0, mixed mode)
Removing intermediate container 7df7e2d8a441
---> 0f7162dae25d
Step 19/20 : RUN ls /sonar-scanner-4.2.0.1873/bin
---> Running in b7efb86cd86e
sonar-scanner
sonar-scanner-debug
sonar-scanner-debug.bat
sonar-scanner.bat
Removing intermediate container b7efb86cd86e
---> ff640a70876f
Step 20/20 : RUN sonar-scanner --help
---> Running in 9164ac2e8369
Could not find 'java' executable in JAVA_HOME or PATH.
The command '/bin/sh -c sonar-scanner --help' returned a non-zero code: 1
Notice which java gives /usr/bin/java. So I set JAVA_HOME=/usr/bin. java can run. But sonar-scanner cannot appear to find java ... why is that?
Add JAVA_HOME ENV according to version, as mentioned #cricket_007 the path in alpine for JDK is /usr/lib/jvm/{VERSION}
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
ENV PATH="$JAVA_HOME/bin:${PATH}"
RUN echo $PATH
run docker
docker run --privileged -it --rm sonar-s sonar-scanner --version
output
INFO: Scanner configuration file: /sonar-scanner-4.2.0.1873/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.5 Alpine (64-bit)
INFO: Linux 4.14.70-67.55.amzn1.x86_64 amd64
I have below function java_install written in a bash script to install java on Linux box, to which I pass jdk-1.7.0_80-linux-x64.tgz as JAVA_PACKAGE.
Now what is happening is java gets installed and works fine only within the script. Once I come out of this script, none of the java functionalities work, not even java -version. Could someone please help me on what I might be missing here? Basically, I just want java to be installed permanently on this box once this script is executed.
java_install() {
local JAVA_PACKAGE=$1
local TMPDIR=/tmp/quickstart
local TARGET=/usr/share
if [ -n "$JAVA_PACKAGE" ] && [ -f "$JAVA_PACKAGE" ]; then
rm -rf $TMPDIR
mkdir -p $TMPDIR
cp $JAVA_PACKAGE $TMPDIR
( cd $TMPDIR && tar fxz $JAVA_PACKAGE && rm $JAVA_PACKAGE )
local JAVA_BASENAME=$(ls -1 $TMPDIR)
mkdir -p $TARGET
if [ -d "$TARGET/$JAVA_BASENAME" ]; then
echo "# Java already installed at $TARGET/$JAVA_BASENAME"
log_info "Java already installed at $TARGET/$JAVA_BASENAME"
else
echo "# Java now installed at $TARGET/$JAVA_BASENAME"
log_info "Java now installed at $TARGET/$JAVA_BASENAME"
mv $TMPDIR/$JAVA_BASENAME $TARGET
fi
rm -rf $TMPDIR
# now create a script to export these settings
export JAVA_HOME=$TARGET/$JAVA_BASENAME
export PATH=$JAVA_HOME/bin:$PATH
else
echo "# cannot find java package to install"
log_error "cannot find java package to install"
fi
}
Use update alternatives within your script to make your java installation available:
sudo update-alternatives --install "/usr/bin/java" "java" "path to you java executable" 1
More information on this topic can be found here: How to use the command update-alternatives --config java.
Alternatively you can write the export commands for JAVA HOME and PATH to your .bashrc from within your script (if using bash). This way the modified variables are available in the bash shell.
I try to install java8 on my Linux server centOS. In /etc/profile
export JAVA_HOME=/root/jdk1.8.0_71/
export PATH=$JAVA_HOME/bin/:$PATH
[root#localhost ~]# echo $JAVA_HOME
/root/jdk1.8.0_71/
[root#localhost ~]# which java
/root/jdk1.8.0_71/bin/java
[root#localhost ~]#
And then I install Cassandra, but it cannot find the java8. And I execute some commands and get
[root#localhost ~]# su cassandra -c "echo $JAVA_HOME"
/root/jdk1.8.0_71/
[root#localhost ~]# su cassandra -c "whereis java"
java: /usr/bin/java /etc/java /usr/lib/java /usr/local/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
[root#localhost ~]# su cassandra -c "which java"
which: no java in (/root/jdk1.8.0_71//bin/:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
I want to know since the PATH is right, why I failed to get java using which java?
And then I create soft link and change the mode of /root/jdk1.8.0_71 to 777
cd /usr/bin
java -> /root/jdk1.8.0_71/bin/java
But it is still not work. Did I miss somethings or make anything wrong?
If the user Cassandra does not have permission on the /root folder then it wont be able to find it. I don't know why would you copy the JDK in the /root folder. My suggestion is to copy the jdk1.8.0_71 in the /opt folder and set the correct permission (owner or group), something like:
cp -r /root/jdk1.8.0_71 /opt
chown -R cassandra.cassandra /opt
Additional, setting paths in the PATH variable should not include the trailing to avoid "/root/jdk1.8.0_71//bin/"