How to download specific version in dockerfile? - java

I'm new at writing dockers. I need to download specific java version for it:
FROM alpine:3.9
RUN apk add bash && apk add openjdk8 && apk add R && apk add perl
this is working, however it downloads the latest version of java - 1.8.0_212.
I need the specific version 1.8.0_171, so I tried the below and it didn't work:
RUN apk add bash && apk add openjdk8=1.8.0_171 && apk add R && apk add perl
Anyone know how to get the specific version?

Try this out
ARG JAVA_VERSION_MAJOR=8
ARG JAVA_VERSION_MINOR=131
ARG JAVA_VERSION_BUILD=11
ARG JAVA_PACKAGE=server-jre
ARG JAVA_SHA256_SUM=a80634d17896fe26e432f6c2b589ef6485685b2e717c82cd36f8f747d40ec84b
ARG JAVA_URL_ELEMENT=d54c1d3a095b4ff2b6607d096fa8016
# Download and unarchive Java
RUN apk add --update curl && \
mkdir -p /opt
RUN wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/${JAVA_URL_ELEMENT}/${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz
RUN mv ${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz java.tar.gz
RUN gunzip -c java.tar.gz | tar -xf - -C /opt && rm -f java.tar.gz && \
ln -s /opt/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR} /opt/jdk
RUN apk add unzip
RUN curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip && \
unzip jce_policy-8.zip -d /tmp && \
cp /tmp/UnlimitedJCEPolicyJDK8/*.jar /opt/jdk/jre/lib/security/ && \
rm -rf jce_policy-8.zip /tmp/UnlimitedJCEPolicyJDK8 && \
apk del curl && \
rm -rf /var/cache/apk/*
ENV JAVA_HOME /opt/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin

this worked for me :
ENV JAVA_VERSION 10.0.2 # your java version
ENV JAVA_HOME /java
RUN apt-get update
RUN apt-get install -y wget cron vim unzip bzip2 && apt-get clean
RUN wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/${JAVA_URL_ELEMENT}/${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
&& mkdir -p $JAVA_HOME \
&& tar -xvzf jdk-10.0.2_linux-x64_bin.tar.gz -C $JAVA_HOME

Related

Nifi stuck at "Launched Apache NiFi with Process ID 41"

I have created a docker image for Nifi 1.14.0 with Alpine OS and jdk-8. I have been able to successfully build it but when I execute "./nifi.sh run" command in docker to run Nifi but it gets stuck at "Launched Apache NiFi with Process ID 41" and doesn't move beyond this unless I do Ctrl+C which shutdowns Nifi. Upon checking the nifi-app.log, it is seen that nar files have been unpacked and no errors are shown. Nifi-bootstrap.log and nifi-user.log don't show any errors eithers. What could be the possible reason and solution for this such that Nifi launches properly?
Thanks in advance!!
My Dockerfile is:
#getting base image Alpine
FROM alpine
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk/jre
ENV PATH $JAVA_HOME/bin:$PATH
ENV NIFI_VERSION 1.14.0
ENV NIFI_HOME /opt/nifi
RUN apk --update add bash git wget ca-certificates sudo openssh rsync openjdk8 zip && \
rm -rf /var/cache/apk/* && \
rm -rf /opt && \
mkdir -p /opt
RUN wget https://dlcdn.apache.org/nifi/$NIFI_VERSION/nifi-$NIFI_VERSION-bin.tar.gz && \
tar xzf nifi-$NIFI_VERSION-bin.tar.gz -C /opt/ && \
ln -s /opt/nifi-$NIFI_VERSION $NIFI_HOME && \
rm nifi-$NIFI_VERSION-bin.tar.gz
RUN apk update --no-cache && apk upgrade --no-cache && apk add --no-cache bash libstdc++ libc6-compat
VOLUME ["$NIFI_HOME/conf"]
EXPOSE 8080
WORKDIR $NIFI_HOME

Adding GDAL to openjdk-alpine based container

I have Spring boot application running on container. The Dockerfile for it is like this:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
CMD ["java", "-jar", "/app.jar"]
In the application there is ogr2ogr command so I want to install GDAL package to container.
I have no idea how I can do this.I feel that I approach the solution the most here.
In this solution, proj was in testing branch of Alpine but now it is in community branch as I understand. So, I added the dependencies of proj and modified Dockerfile like this:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENV ROOTDIR /usr/local
ENV LD_LIBRARY_PATH /usr/local/lib
ENV GDAL_VERSION 3.1.2
ENV OPENJPEG_VERSION 2.3.0
# Load assets
WORKDIR $ROOTDIR/
RUN mkdir -p $ROOTDIR/src
RUN wget -qO- \
http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz | \
tar -xzC $ROOTDIR/src/
RUN wget -qO- \
https://github.com/uclouvain/openjpeg/archive/v${OPENJPEG_VERSION}.tar.gz | \
tar -xzC $ROOTDIR/src/
RUN set -ex \
# Install runtime dependencies
&& apk add --update --no-cache \
git \
bash-completion \
python-dev \
python3-dev \
libffi-dev \
jpeg-dev \
openjpeg-dev \
libpng-dev \
linux-headers \
curl-dev \
musl \
libjpeg-turbo \
libcurl \
zlib \
libgcc \
libstdc++ \
musl \
sqlite-libs \
tiff \
&& apk add --no-cache \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/community \
proj \
proj-dev \
# Install common build dependencies
&& apk add --no-cache --virtual .build-deps \
gcc \
cmake \
build-base \
make \
swig \
apache-ant \
# Compile and install OpenJPEG
&& cd src/openjpeg-${OPENJPEG_VERSION} \
&& mkdir build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$ROOTDIR \
&& make -j3 && make -j3 install && make -j3 clean \
&& cd $ROOTDIR && rm -Rf src/openjpeg* \
# Compile and install GDAL
&& cd src/gdal-${GDAL_VERSION} \
&& ./configure --with-python --with-curl --with-java=${JAVA_HOME} --with-openjpeg=$ROOTDIR \
&& make -j3 && make -j3 install \
# Compile Python and Java bindings for GDAL
&& cd $ROOTDIR/src/gdal-${GDAL_VERSION}/swig/java && make -j3 && make -j3 install \
&& cd $ROOTDIR/src/gdal-${GDAL_VERSION}/swig/python \
&& python3 setup.py build \
&& python3 setup.py install \
&& cd $ROOTDIR && rm -Rf src/gdal* \
# Remove build dependencies
&& apk del .build-deps \
CMD ["java", "-jar", "/app.jar"]
Then the output of docker build is:
15 176.1 checking for ld used by GCC... /usr/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64
#15 176.1 checking if the linker (/usr/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64) is GNU ld... yes
#15 176.1 checking for shared library run path origin... /bin/sh: can't open './config.rpath': No such file or directory
#15 176.1 done
#15 176.1 checking for iconv... yes
#15 176.2 checking for working iconv... yes
#15 176.2 checking for iconv declaration...
#15 176.2 extern size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
#15 176.3 using ICONV_CPP_CONST=""
#15 176.3 configure: Bash completions not requested
#15 176.3 checking for PROJ >= 6 library... checking for proj_create_from_wkt in -lproj... no
#15 176.3 checking for internal_proj_create_from_wkt in -lproj... no
#15 176.4 checking for internal_proj_create_from_wkt in -linternalproj... no
#15 176.4 configure: error: PROJ 6 symbols not found
------
executor failed running [/bin/sh -c set -ex && apk add --update --no-cache git bash-completion python-dev python3-dev libffi-dev jpeg-dev openjpeg-dev
libpng-dev linux-headers curl-dev musl libjpeg-turbo libcurl zlib libgcc libstdc++ musl sqlite-libs tiff && apk add --no-cache
--repository http://dl-cdn.alpinelinux.org/alpine/edge/community proj proj-dev && apk add --no-cache --virtual .build-deps gcc cmake build-base make
swig apache-ant && cd src/openjpeg-${OPENJPEG_VERSION} && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$ROOTDIR && make -j3 && make -j3 install &
& make -j3 clean && cd $ROOTDIR && rm -Rf src/openjpeg* && cd src/gdal-${GDAL_VERSION} && ./configure --with-python --with-curl --with-java=${JAVA_HOME} --with-openjpeg=$ROOTDIR && make -j3 && m
ake -j3 install && cd $ROOTDIR/src/gdal-${GDAL_VERSION}/swig/java && make -j3 && make -j3 install && cd $ROOTDIR/src/gdal-${GDAL_VERSION}/swig/python && python3 setup.py build && python3 setup.p
y install && cd $ROOTDIR && rm -Rf src/gdal* && apk del .build-deps CMD ["java", "-jar", "-Dlogging.config=/logback.xml", "/app.jar"]]: exit code: 1
Let me emphasize that I do not know about Alpine Linux and GDAL. I tried to do something based on a solution I found.

OpenJDK 15 and Docker

I want to get Docker running with JDK 15 I am following https://github.com/markhobson/docker-maven-chrome/blob/master/jdk-15/Dockerfile but I get ADD failed: stat /var/lib/docker/tmp/docker-builder165793576/google-chrome.repo: no such file or directory
My Docker file is:
FROM maven:3.6.3-openjdk-15
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
## Google Chrome
ARG CHROME_VERSION=87.0.4280.88-1
ADD google-chrome.repo /etc/yum.repos.d/google-chrome.repo
RUN microdnf install -y google-chrome-stable-$CHROME_VERSION \
&& sed -i 's/"$HERE\/chrome"/"$HERE\/chrome" --no-sandbox/g' /opt/google/chrome/google-chrome
# ChromeDriver
ARG CHROME_DRIVER_VERSION=87.0.4280.88
RUN microdnf install -y unzip \
&& curl -s -o /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip \
&& unzip /tmp/chromedriver.zip -d /opt \
&& rm /tmp/chromedriver.zip \
&& mv /opt/chromedriver /opt/chromedriver-$CHROME_DRIVER_VERSION \
&& chmod 755 /opt/chromedriver-$CHROME_DRIVER_VERSION \
&& ln -s /opt/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver
###
ENTRYPOINT ["java","-jar","/app.jar"]
Does anyone know how to fix? I do not have a file google-chrome.repo - does anyone know the best way to get that?
I got it to work with the following Docker File:
FROM maven:3.6.3-openjdk-15
# Google Chrome
ARG CHROME_VERSION=87.0.4280.88-1
ADD google-chrome.repo /etc/yum.repos.d/google-chrome.repo
RUN microdnf install -y google-chrome-stable-$CHROME_VERSION \
&& sed -i 's/"$HERE\/chrome"/"$HERE\/chrome" --no-sandbox/g' /opt/google/chrome/google-chrome
## ChromeDriver
ARG CHROME_DRIVER_VERSION=87.0.4280.88
RUN microdnf install -y unzip \
&& curl -s -o /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip \
&& unzip /tmp/chromedriver.zip -d /opt \
&& rm /tmp/chromedriver.zip \
&& mv /opt/chromedriver /opt/chromedriver-$CHROME_DRIVER_VERSION \
&& chmod 755 /opt/chromedriver-$CHROME_DRIVER_VERSION \
&& ln -s /opt/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
where google-chrome.repo is:
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub

Dockerfile: Multi-stage builds not working and any python3 + alpine + java image readily available

I am containerizing a component. It requires Linux + Python and Java.
Linux + Python - I am using Alpine 3.5 & Python 3.5 image.
Here is my Docker file.
Dockerfile:
#
# Health Monitoring Docker File
#
#ARG JAVA_BASE=1.0
#FROM csf-docker-delivered.repo.lab.pl.alcatel-lucent.com/java_base:17.6-1
#WORKDIR /etc/alternatives
#RUN CGO_ENABLED=0
FROM registry1-docker-io.repo.lab.pl.alcatel-lucent.com/python:3.5-alpine
#COPY --from=build /etc/alternatives/* .
#RUN rm -rf /var/cache/apk/* && \
# rm -rf /tmp/*
#
#RUN apk update
#
#RUN apk add --update --no-cache\
# build-base \
# openjdk8-jre \
# && pip install virtualenv \
# && rm -rf /var/cache/apk/*
#RUN apk update && apk upgrade && \
# apk add openjdk8 && \
# mkdir /tmp/tmprt && \
# cd /tmp/tmprt && \
# apk add zip && \
# unzip -q /usr/lib/jvm/default-jvm/jre/lib/rt.jar && \
# apk add zip && \
# zip -q -r /tmp/rt.zip . && \
# apk del zip && \
# cd /tmp && \
# mv rt.zip /usr/lib/jvm/default-jvm/jre/lib/rt.jar && \
# rm -rf /tmp/tmprt /var/cache/apk/* bin/jjs bin/keytool bin/orbd bin/pack200 bin/policytool \
# bin/rmid bin/rmiregistry bin/servertool bin/tnameserv bin/unpack200
COPY ./jdk-8u201-linux-x64.tar.gz /
RUN tar xf /jdk-8u201-linux-x64.tar.gz
ENV JAVA_HOME=/jdk1.8.0_201/bin
ENV NGDB_HOME /opt/nsn/ngdb
#RUN yum -y install openjdk-8-jdk-headless
#RUN apt-get install openjdk-8-jdk-headless
#COPY ./openjdk-8_8u181-b13.orig.tar.gz /
#RUN tar xf /openjdk-8_8u181-b13.orig.tar.gz
RUN mkdir -p /opt/nsn/ngdb/monitoring/scripts
RUN mkdir -p /opt/nsn/ngdb/monitoring/utils
RUN mkdir -p /var/local/monitoring/output
RUN mkdir -p /var/local/monitoring/work
RUN for directory in boundaryStatus postgresUsersCount backlogHadoop tableCount_Usage Dimension_Count tableCount_Day tableCount_Week tableCount_Month sendSummaryReport; do mkdir -p $directory;done
COPY ./utils/* /opt/nsn/ngdb/monitoring/utils/
COPY ./scripts/* /opt/nsn/ngdb/monitoring/scripts/
COPY ./conf/* /opt/nsn/ngdb/monitoring/conf/
COPY ./postgresql-9.2-1004.jdbc4.jar /opt/nsn/ngdb/monitoring/utils/
RUN mkdir -p /opt/nsn/ngdb/monitoring/python-dependencies
COPY ./html3-1.17.tar.gz /opt/nsn/ngdb/monitoring/python-dependencies
COPY ./py4j-0.10.8.1.zip /opt/nsn/ngdb/monitoring/python-dependencies
#RUN tar xf /opt/nsn/ngdb/monitoring/python-dependencies/html3-1.17.tar.gz
#WORKDIR /html3-1.17/
#RUN python /html3-1.17/setup.py install
RUN unzip /opt/nsn/ngdb/monitoring/python-dependencies/py4j-0.10.8.1.zip
WORKDIR /py4j-0.10.8.1
RUN python /py4j-0.10.8.1/setup.py install
But if i try to add Java Image & Python Alpine Image using "FROM", I am able to get only one thing in my container.
When i searched, i came across Multi stage builds, but when i did like below it is throwing a error "Unknown flag: from"
FROM csf-docker-delivered.repo.lab.pl.alcatel-lucent.com/java_base:17.6-1
WORKDIR /etc/alternatives
FROM registry1-docker-io.repo.lab.pl.alcatel-lucent.com/python:3.5-alpine
COPY --from=0 /etc/alternatives/* .
Can some one please help me out?
And addition to this,
I am trying to install py4j as a external module through which i am calling java classes.
i have set WORKDIR and then installation of py4j module goes smooth.
Later if i try to set WORKDIR to other module ex: html, and when i try
RUN python setup.py install
It gives error stating "No Such file or Directory"
Can you please help on this?

Docker and Java 9 modules

Are there Docker images for specific Java 9 modules?
I guess there should appear base images for FROM java:9, but how would optional modules come, if my base would be from minimal core Java 9 module.
Here is one example:
FROM java:9
COPY /target/myswarmproject-swarm.jar /home/myswarm-swarm.jar
EXPOSE 8080
CMD java -jar /home/myswarmproject-swarm.jar
Previous dockerfile example is for wildfly swarm project which is deployed as .jar into the container.
Here is my implementation, also found at adenix/java:9u181:
FROM ubuntu:16.04
RUN \
apt update && \
apt install -y curl && \
curl -jkL -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_linux-x64_bin.tar.gz -o jdk-9_linux-x64_bin.tar.gz && \
apt remove -y curl && \
apt clean && \
apt -y autoremove && \
rm -rf /var/lib/apt/lists/* && \
tar xvzf jdk-9_linux-x64_bin.tar.gz -C /opt/ && \
rm -rf jdk-9_linux-x64_bin.tar.gz && \
update-alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 100 && \
update-alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 100 && \
update-alternatives --install /usr/bin/jshell jshell /opt/jdk-9/bin/jshell 100
CMD ["jshell"]
You could implement this by either duplicating this Docker file or using FROM adenix/java:9u181 in your Dockerfile.

Categories