how to install java into azure docker environment? [duplicate] - java

I am trying to create a docker image from my docker file which has the following content:
FROM ubuntu:14.04.4
RUN echo 'deb http://private-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.4.2.0 HDP main' >> /etc/apt/sources.list.d/HDP.list
RUN echo 'deb http://private-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main' >> /etc/apt/sources.list.d/HDP.list
RUN echo 'deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/azurecore/ trusty main' >> /etc/apt/sources.list.d/azure-public-trusty.list
RUN gpg --keyserver pgp.mit.edu --recv-keys B9733A7A07513CAD
RUN gpg -a --export 07513CAD | apt-key add -
RUN gpg --keyserver pgp.mit.edu --recv-keys B02C46DF417A0893
RUN gpg -a --export 417A0893 | apt-key add -
RUN apt-get update
which fails with the following error:
root#sbd-docker:~/ubuntu# docker build -t hdinsight .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM ubuntu:14.04.4
---> 8f1bd21bd25c
Step 2 : RUN echo 'deb http://private-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.4.2.0 HDP main' >> /etc/apt/sources.list.d/HDP.list
---> Using cache
---> bc23070c0b18
Step 3 : RUN echo 'deb http://private-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main' >> /etc/apt/sources.list.d/HDP.list
---> Using cache
---> e45c32975e28
Step 4 : RUN echo 'deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/azurecore/ trusty main' >> /etc/apt/sources.list.d/azure-public-trusty.list
---> Using cache
---> 1659cdcab06e
Step 5 : RUN gpg --keyserver pgp.mit.edu --recv-keys B9733A7A07513CAD
---> Using cache
---> ca73b2bfcd21
Step 6 : RUN gpg -a --export 07513CAD | apt-key add -
---> Using cache
---> 95596ad10bc9
Step 7 : RUN gpg --keyserver pgp.mit.edu --recv-keys B02C46DF417A0893
---> Using cache
---> f497deeef5b5
Step 8 : RUN gpg -a --export 417A0893 | apt-key add -
---> Using cache
---> d01dbe7fa02e
Step 9 : RUN apt-get update
---> Running in 89d75799982f
E: The method driver /usr/lib/apt/methods/https could not be found.
The command '/bin/sh -c apt-get update' returned a non-zero code: 100
root#sbd-docker:~/ubuntu#
I am running this on Ubuntu 14.04.4.
I tried restarting docker, cleaning up all docker images, installing apt-transport-https, but nothing worked.
I dont know whats wrong here.

Because you have an https sources. Install apt-transport-https before executing update.
FROM ubuntu:14.04.4
RUN apt-get update && apt-get install -y apt-transport-https
RUN echo 'deb http://private-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.4.2.0 HDP main' >> /etc/apt/sources.list.d/HDP.list
RUN echo 'deb http://private-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main' >> /etc/apt/sources.list.d/HDP.list
RUN echo 'deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/azurecore/ trusty main' >> /etc/apt/sources.list.d/azure-public-trusty.list
....
Rest of your Dockerfile.

I had to clean up my disk with docker system prune, I did it because I read about it on this other SO answer

Just adding this in case it's of use to someone else. In my case I had to add the following line to the Dockerfile:
RUN apt-get -y update

I encountered the same problem because my Dockerfile's FROM line refers to Ubuntu 20.10 whose support ended July 2021:
FROM ubuntu:groovy-20210416
Updating this to:
FROM ubuntu:focal-20211006
resolved the issue for me.

I had the same problem, solved it thanks to this answer :
https://superuser.com/questions/1423486/issue-with-fetching-http-deb-debian-org-debian-dists-jessie-updates-inrelease/1424377
You may want to add this line
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
before any apt-get command in the Dockerfile.

in my case the error was
The repository 'http://internalrepo/repos/internalrepo-name/1 Release' does not have a Release file.
adding [trusted=yes] before the deb package name fixed the issue.
i.e.
deb [trusted=yes] http://internalrepo/repos/internalrepo-name/1 /

Check your time settings. They may be not in sync with target http|https repository.

Based on #Jonathan Morales VĂ©lez 's answer (running out of disk space), the following command helped me to reclaim disk space:
docker image prune -f
Afterwards the Docker Image build resumed working.

in some cases that might be a network issue and trying in few hours later or with an other network might fix that

Had the same problem, fixed it using the following command
RUN apt -y update ; exit 0

Related

japp.jar is not found when building docker image

I'm very much new to docker. I have a node application that process/read a java file. I'm trying to create a docker image that runs node and java. I node configs are working well but I'm always getting errors when building the docker file because of java - it shows
failed to compute cache key: "/japp.jar" not found: not found"
My Dockerfile contains:
FROM node:14.18.1
RUN apt-get update && apt-get -y upgrade
WORKDIR /code
EXPOSE 8443
COPY package.json /code/package.json
RUN npm install
COPY . /code
# Jave Config
FROM eclipse-temurin:11
RUN mkdir /opt/app
COPY japp.jar /opt/app
ENTRYPOINT ["java", "-jar", "/opt/app/japp.jar"]
CMD ["node","app.js"]
I was trying to follow the docs here but no luck.
In the past, I was using the following for Java config and that was working fine, but it shows some vulnerability so I need to switch to eclipse-temurin:11
# RUN echo 'deb http://ftp.debian.org/debian stretch-backports main' | tee /etc/apt/sources.list.d/stretch-backports.list
# RUN apt-get update && apt-get -y upgrade && \
# apt-get install -y openjdk-11-jre-headless && \
# apt-get clean;

installing tomcat on top of ubuntu in docker

I am new to docker and trying to install tomcat on top of ubuntu using a Dockerfile.
but getting error building an image from the Dockerfile.
Error saying...
Sending build context to Docker daemon 12.8kB
Step 1/12 : FROM ubuntu:latest
---> d13c942271d6
Step 2/12 : MAINTAINER xyz
---> Using cache
---> 83dbc04930a4
Step 3/12 : RUN mkdir /opt/tomcat/
---> Using cache
---> 1e167fd46a0e
Step 4/12 : WORKDIR /opt/tomcat/
---> Using cache
---> 26c7316b8e12
Step 5/12 : RUN apt-get update && apt-get install -y curl
---> Using cache
---> b0138decc33d
Step 6/12 : RUN curl -O https://www-eu.apache.org/dist/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz
---> Using cache
---> eda41a539c78
Step 7/12 : RUN tar -xvzf apache-tomcat-8.5.50.tar.gz
---> Running in cc9f646b2bb2
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
The command '/bin/sh -c tar -xvzf apache-tomcat-8.5.50.tar.gz' returned a non-zero code: 2
and my code is
FROM ubuntu: latest
MAINTAINER ganeshthirumani
RUN mkdir /opt/tomcat/
WORKDIR /opt/tomcat/
RUN apt-get update && apt-get install -y curl
RUN curl -O https://www-eu.apache.org/dist/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz
RUN tar -xvzf apache-tomcat-8.5.50.tar.gz
RUN mv apache-tomcat-8.5.50/* /opt/tomcat/.
WORKDIR /opt/docker-tomcat/tomcat/webapps
RUN curl -O -L https://github.com/AKSarav/SampleWebApp/raw/master/dist/SampleWebApp.war
EXPOSE 3000
CMD ["/opt/tomcat/bin/catalina.sh", "run"]
I am trying to understand the code as it was suggested by one of my friends,
as my understanding:
at line
fixing the base image as ubuntu
this is the metadata of the person who is maintaining the code, it may be organizational
3,4. working directory, here we have two working directories, one to run docker commands and another is to deploy the war file
is to install the curl on docker
6-10. I did not understand anything.
is to make the localhost to run the tomcat
cmd to run the container
I am trying but I was not able to what It means...
it would be helpful if anyone respond...
Thank you so much...

Update gitlab JDK to JDK17 (VM doesn't have internet connection)

I am using Gitlab to build a Java tool using ant
The tool requires JDK 17, but ant JDK version is 11, and I'm trying to change it.
So I tried a lot of solutions using a remote repository or remote download site, but after some tries I found out that the VM used to build the tool is not connected to internet (trying to ping google or my IP address doesn't work).
So I tried to upload in the same package with the tool source code the JDK 17 (openjdk-17_linux-x64_bin.tar.gz) and install it there.
Here is the problem, I am not sure how to do this since I don't work with linux, but I tried almost everything on the internet.
Every of these commands are used in a .gitlab-ci.yml file, used for gitlab pipeline.
Here are some examples of what I've tried so far:
- sudo cp /builds/project/openjdk-17_linux-x64_bin.tar.gz /usr/lib/jvm
- sudo tar zxvf "/usr/lib/jvm/openjdk-17_linux-x64_bin.tar.gz" -C /usr/lib/jvm
- echo "JAVA_HOME=/usr/lib/jvm/jdk-17" | sudo tee -a /etc/profile
- echo "PATH=${PATH}:${HOME}/bin:${JAVA_HOME}/bin" | sudo tee -a /etc/profile
- echo "export JAVA_HOME" | sudo tee -a /etc/profile
- echo "export JRE_HOME" | sudo tee -a /etc/profile
- echo "export PATH" | sudo tee -a /etc/profile
- sudo cat /etc/profile
- echo "JAVA_HOME=/usr/lib/jvm/jdk-17" | sudo tee -a /.bashrc
- echo "PATH=${PATH}:${JAVA_HOME}/bin" | sudo tee -a /.bashrc
- echo "JAVA_HOME='/usr/lib/jvm/jdk-17' | sudo tee -a /etc/environment"
- export JAVA_HOME=/usr/lib/jvm/jdk-17
- export PATH=$PATH:$JAVA_HOME/bin
After a lot of combinations of these commands the output of sudo update-alternatives --config java is still:
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode, sharing)
But if I try /usr/lib/jvm/jdk-17/bin/java -version it prints 17.
What would be the solution of making the default Java version to be 17. (Also a solution for ant to use the JDK-17 without installing it would be great too, since I need the JDK-17 for ant)
Since you've already found a way to change the jdk on-the-go, you may really want to consider change the base image of your CI to save yourself a lot of time. This step will boost your CI speed. The steps to do that is fairly simple too.
Compose your own Dockerfile
This following is just a pesudo code. You may look into the description of dockerfile builder
FROM your-original-image. This is what you have in your image tag in the gitlab-ci file.
COPY jdk-17-linux-x64.tar.gz /usr/lib/jvm
RUN sudo tar zxvf "/usr/lib/jvm/jdk-17-linux-x64.tar.gz" -C /usr/lib/jvm \
&& sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/java-1.11.0-openjdk-amd64 \
&& sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/default-java \
&& sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/java-11-openjdk-amd64 \
&& sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/openjdk-11 \
&& sudo update-alternatives --remove-all java \
&& sudo update-alternatives --remove-all javac \
&& sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-17/bin/java 1
Build the docker image
If you are using docker hub, then you need to login to docker and get a dockerId which matches the dockerId in the snippet.
If you are using a private repo like harbor or artifactory, you may need the permission to push to it.
docker build . -t dockerId/Name-of-your-image-you-want:latest
Upload the docker image using docker push
docker push dockerId/Name-of-your-image-you-want:latest
change the image tag in your gitlab-ci.yaml to dockerId/Name-of-your-image-you-want:latest
I found a solution.
- sudo cp jdk-17-linux-x64.tar.gz /usr/lib/jvm
- sudo tar zxvf "/usr/lib/jvm/jdk-17-linux-x64.tar.gz" -C /usr/lib/jvm
- sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/java-1.11.0-openjdk-amd64
- sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/default-java
- sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/java-11-openjdk-amd64
- sudo \cp -r /usr/lib/jvm/jdk-17 /usr/lib/jvm/openjdk-11
- sudo update-alternatives --remove-all java
- sudo update-alternatives --remove-all javac
- sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-17/bin/java 1
What I did here was to copy the JDK-17 content to all folders from /usr/lib/jvm folder. So even though the docker image uses JDK-11, I'm rewriting it using JDK-17 uploaded with the source code, and now the tool is built using JKD-17.
PS: I know this is slower and not professional, but in my case, it's easier and more convinient than trying to get help from those who setup the docker container.

Unable to stop java process using SIGINT on Linux

I am building a virtual machine for some tests that needs to run among other things DynamoDb web service. VM is based on stock Ubuntu 16.04 64bit.
This is the part of provisioning script that installs DynamoDB:
# Install local instance of DynamoDB
DARCHFILE='/tmp/dynamodb_local_latest.zip'
wget -P /tmp/ -nv https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip
sudo unzip -q "$DARCHFILE" -d /usr/local/lib/dynamodb
sudo mkdir -pv /var/lib/dynamodb/
sudo mkdir -pv /var/log/dynamodb/
sudo apt-get install -y openjdk-8-jdk
This is the script that executes DynamoDb:
#!/bin/bash
# -*- mode: sh -*-
# vi: set ft=sh :
java -Djava.library.path=/usr/local/lib/dynamodb/DynamoDBLocal_lib/ \
-jar /usr/local/lib/dynamodb/DynamoDBLocal.jar \
-dbPath /var/lib/dynamodb/ \
-optimizeDbBeforeStartup \
-port 8000 > /var/log/dynamodb/trace.log 2> /var/log/dynamodb/error.log &
echo $! > /var/run/dynamodb.pid
Now if I try to stop the process using the "nice one" SIGINT (equivalent of Ctrl+C) it does nothing. Only sending SIGTERM works.
So this does nothing:
sudo kill -s SIGINT $(< /var/run/dynamodb.pid)
As we can confirm by executing this:
sudo ps -x | grep $(< /var/run/dynamodb.pid)
While this works just fine:
sudo kill -s SIGTERM $(< /var/run/dynamodb.pid)
On the other hand if I start dynamodb manually and don't send it to the background Ctrl+C does work.
So what gives? Is it my mistake or behavior by design?
Thanks

Install Java 8 in debian Jessie

I've tried to install Java 8 into a ARM embedded linux in several ways but none of them worked:
First:
http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html
(from the repositories of webupd8)
W: Failed to fetch
http://ppa.launchpad.net/webupd8team/java/ubuntu/dists/trusty/InRelease
Unable to find expected entry 'main/binary-armel/Packages' in Release
file (Wrong sources.list entry or malformed file)
W: Failed to fetch
http://ppa.launchpad.net/webupd8team/java/ubuntu/dists/jessie/main/binary-armel/Packages
404 Not Found
E: Some index files failed to download. They have been ignored, or old
ones used instead.
It seems that this repo does not have the source for my architecture:
Architectures: amd64 arm64 armhf i386 powerpc ppc64el
And i need armel ( at least this is working for java 7 )
I also tried this way:
http://www.rpiblog.com/2014/03/installing-oracle-jdk-8-on-raspberry-pi.html
Downloading the jdk from Oracle and then following the instructions.
But i cannot execute the file :
root#arietta:~# java -version
-bash: /usr/bin/java: No such file or directory
and neither:
root#arietta:~# /opt/jdk1.8.0_71/bin/java -version
-bash: /usr/bin/java: No such file or directory
While the file exists and has the correct permissions... i'm going crazy..
Any idea or alternative method?
At the end i solved it adding jessie backports to the sources.list:
echo deb http://http.debian.net/debian jessie-backports main >> /etc/apt/sources.list
apt-get update && apt-get install openjdk-8-jdk
update-alternatives --config java
I ran the following commands from the webupd8 team and it worked for me:
http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html
su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java8-installer
exit
Same as #user2528085, you just need to add Debian backports to your sourcelist file.
Follow this instruction on Debian official site
https://backports.debian.org/Instructions/
Run these commands in shell:
echo "deb http://ftp.debian.org/debian jessie-backports main" | sudo tee -a /etc/apt/sources.list.d/jessie-backports.list
sudo apt-get update && sudo apt-get install elasticsearch
Nothing difficult

Categories