java-8-openjdk-amd64 does not exist in container - java

I keep receiving the below error when trying to run this hadoop docker container
docker run -it --name psu-hadoop-container -p 2222:22 -p 8042:8042 -p 9864:9864 -p
9870:9870 -p 8088:8088 -p 10000:10000 -p 19888:19888 psu-hadoop
ERROR: JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 does not exist.
ERROR: JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 does not exist.
ERROR: JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 does not exist.
ERROR: JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 does not exist.
ERROR: JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 does not exist.
I'm working on a Mac. The DockerFile references the path java-8-openjdk-amd64 but I don't have that specific software, just jdk-19.jdk.
The Dockerfile is from a class and the class primarily uses PC.
Do I need to modify my JAVA_HOME? Do I need to modify the path in the Dockerfile?

The Java version on your host doesn't matter.
If you have an M1/M2 Mac, then they won't run amd64 images unless you emulate it using --platform=linux/amd64.
Sounds like you'll also need to rebuild the Dockerfile with the same.
https://docs.docker.com/build/building/multi-platform/

Related

JAVA_HOME should point to a JDK not a JRE + JAVA_HOME is not defined correctly

I've edited my .bashrc file on my server, with sudo nano ~/.bashrc
export JAVA_HOME=/usr/bin/java
export PATH=${PATH}:${JAVA_HOME}/bin
I've re-logged in, and here is all the path as output:
root#ubuntu-s-1vcpu-1gb-blr1-01:~/maifee/backend-spring# echo $JAVA_HOME
/usr/bin/java
root#ubuntu-s-1vcpu-1gb-blr1-01:~/maifee/backend-spring# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin/java/bin
But when I try to run my spring boot server, it gives me:
root#ubuntu-s-1vcpu-1gb-blr1-01:~/maifee/backend-spring# ./mvnw spring-boot:run
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/bin/java/bin/java
And when I try to do a mvn install, I get:
root#ubuntu-s-1vcpu-1gb-blr1-01:~/maifee/backend-spring# mvn install
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
But here is the java configuration list:
root#ubuntu-s-1vcpu-1gb-blr1-01:~/maifee/backend-spring# sudo update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
And when I try to run(just tried, without installing dependencies), I get:
root#ubuntu-s-1vcpu-1gb-blr1-01:~/maifee/backend-spring# ./mvnw spring-boot:run
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/bin/java/bin/java
How can I set up my environment to correctly, run my Spring Boot server? I directly have source code there, I don't even need compiling and stuffs.
JAVA_HOME sould point to the base installation dir of java:
/usr/lib/jvm/java-11-openjdk-amd64/ not /usr/bin/java which probably is a symbolic link to /usr/lib/jvm/java-11-openjdk-amd64/bin/java
then in PATH variable you append $JAVA_HOME/bin
So it should look something like this:
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
PATH=$JAVA_HOME/bin:$PATH
FYI update-alternatives is only responsible for changing the symlink of java to point it to different versions of the executable,
think of it as a simple ln -s /usr/lib/jvm/java-11-openjdk-amd64/bin/java /usr/bin/java

Google App Engine: JAVA command not recognized by Python in Flex environment with Docker (`java` command is not found from this Python process)

I deployed a Python project on Google App Engine. As the project has a dependency on Java, I used a Docker container configuring two environments: Python + Java.
However, when I make a call to my Python service in GAE it's getting "java command is not found from this Python process. Please ensure Java is installed and PATH is set for java" error.
During the build process of the Docker file I am able to access Java after installing it. But during API execution it is not recognized by Python.
The "app.yaml" file used:
runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.main:app
Below are the the Docker file used in Deploy:
### 1. Get Linux
FROM alpine:3.7
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
### 2. Get Java via the package manager
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
RUN export JAVA_HOME
ENV PATH $PATH:$JAVA_HOME/bin
RUN export PATH
RUN find / -name "java"
RUN java -version
FROM python:3.7
EXPOSE 8080
ENV APP_HOME /src
WORKDIR /src
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
COPY . /src
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]
Here is a printout of the RUN java -version command during the deploy process:
RUN java -version command
Does anyone know why the error is happening even with Python and Java running on the same service on App Engine?
Are there any additional settings missing?
You are using two FROM in a Dockerfile, so you're effectively doing a multi-stage Docker build, but you are doing it wrong.
A multi-stage build should be something like this:
### 1. Get Linux
FROM alpine:3.7 as build
# here you install with apk and build your Java program
FROM python:3.7
EXPOSE 8080
...
# here you copy what you need from the previous Docker build, though
# since it was Java, which is not installed here anymore because it is
# a python image, you need to consider if you really need a multi-stage
# build
COPY --from=builder /src /src
Otherwise, just remove the second FROM python:3.7 and install it with apk.

Installing Oracle Java 11 on Alpine Linux with Docker

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

What changes\setups I need to make to run java in docker over WSL(windows-subsystem-for-linux)?

I'm running the docker command in windows command line successfully but when I run the same command in windows-subsystem-for-linux it shows class not found exception.
windows:
docker run -it --cpus 4 -v ${PWD}:/app --workdir /app adoptopenjdk/openjdk11 java -cp C:\path\to\class Helloworld.java
WSL:
docker run -it --cpus 4 -v ${PWD}:/app --workdir /app adoptopenjdk/openjdk11 java -cp /path/to/class Helloworld.java
Expected output:
Hello world!!
Error:
Could not find or load main class Helloworld.java
Caused by: java.lang.ClassNotFoundException: Helloworld.java
It seems like the path may be wrong
You can also access your local machine’s filesystem from within the
Linux Bash shell – you’ll find your local drives mounted under the
/mnt folder. For example, your C: drive is mounted under /mnt/c:
-- https://learn.microsoft.com/en-us/windows/wsl/faq#what-can-i-do-with-wsl

Jenkins: how to set default JDK for all Piplines

we have configured a couple JDKs in our Jenkins, which are: JDK8, JDK9, JDK11 etc. The Jenkins itself is running under JDK8. Now, we want to get Jenkins to use JDK9 in all Pipelins, if the "tools" statement isn't in pipeline's definition. Is there a way to do that?
Thank You very much!
Defining a JAVA_HOME environment variable in the Jenkins environment will be enough:
export JAVA_HOME = /path/to/JDK9
if you run Jenkins in a container, just define JAVA_HOME in the docker run command:
docker run -d -p 8080:8080 -p 50000:50000 -v /path/to/JDK9:/internal/path/to/JDK9 --env JAVA_HOME=/internal/path/to/JDK9 jenkins:jenkins

Categories

Resources