docker - installing java 8 with curl - java

To insall java 8 on docker container, I used this command in dockerfile
RUN curl -LO 'http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.rpm'
-H 'Cookie: oraclelicense=accept-securebackup-cookie' RUN rpm -i jdk-8u111-linux-x64.rpm RUN rm jdk-8u111-linux-x64.rpm
It worked for awhile, but now this link is not no longer available. Is there replaceable url for this? or easy way to insall java 8 on docker?

It's up to your using OS, so I'd like you to show your OS. For example, Ubuntu users prepares their ppa repository for Oracle Java.
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update
RUN apt-get install oracle-java8-installer

It seems that Oracle has changed the authorization for downloading, the actual link that the browser uses is http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm?AuthParam=1496223138_c808095f7637d83147c37d69d3a87e7a, but this cannot be used with curl.
I have no solution for the problem with downloading from Oracle, but I use the official OpenJDK image as base and have found no problems with that.

If openjdk is OK for you, you can use
RUN apt-get install -y openjdk-8-jdk
openjdk, in contrast to oracle, does not require user's confirmation.
If you only need java runtime, consider openjdk-8-jre.

Adaption of my Dockerfile from https://hub.docker.com/r/sftech/java
FROM ubuntu
ENV JAVA_VERSION=8
RUN echo oracle-java${JAVA_VERSION}-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get update \
&& apt-get install -y software-properties-common \
&& apt-add-repository ppa:webupd8team/java \
&& apt-get update \
&& apt-get install -y oracle-java${JAVA_VERSION}-installer \
&& update-java-alternatives -s java-${JAVA_VERSION}-oracle \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Why would you install java in an image / container, when you can get a java:8 image from the Docker store for free. The license requirements are exactly the same as the java / jdk download install from the oracle.com website.

Related

Docker how to reduce size of specific image

I am totally newbie to Docker. My task is to create such environment to be able to work Spring Boot app on in and what's more I want to have also Heroku CLI installed also (I perform operations between databases on two different accounts using heroku:pg copy). What's more its size should be as small as it is possible and reach max 500MB (would be best if even less) that is quota for Heroku account
Here is my Dockerfile:
FROM ubuntu
# Install OpenJDK-8
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
# Install sudo
RUN apt-get update && \
apt-get -y install sudo
# Add user and switch to it
RUN useradd -m login && echo "login:password" | chpasswd && adduser login sudo
USER login
# Install curl and use curl
RUN echo "password" | sudo -S apt --assume-yes install curl
RUN echo "password" | sudo -S curl https://cli-assets.heroku.com/install.sh -o ~/heroku.sh
# Run Heroku script
RUN echo "password" | sudo -S sh ~/heroku.sh
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
# Add an app and listen on port
ADD target/project-server-1.0-SNAPSHOT.jar .
COPY project-91878452-firebase-adminsdk-dxv9z-0db48a2d01.json /
EXPOSE 8000
CMD java -jar project-server-1.0-SNAPSHOT.jar
This code works, I tested that locally but on Heroku there is an error on start saying that size has been considerably exceeded.
So what should I change in Dockerfile to make image size based on this Dockerfile as small as it is possibke and meet the requirements mentioned at the beginning of the post?
Kind regards!

How to install java 8 using dockerfile in python:3.8-slim-buster base image

Below is my Dockerfile
FROM python:3.8-slim-buster
WORKDIR /app
RUN python --version
RUN apt-get install java-1.8.0-openjdk-devel
RUN python -m pip install --upgrade pip
RUN pip install --default-timeout=100 pyspark
I want to install java 8 and set JAVA_HOME variables. But when I am trying to build above image I am getting below error:
E: Unable to locate package java-1.8.0-openjdk-devel
E: Couldn't find any package by glob 'java-1.8.0-openjdk-devel'
E: Couldn't find any package by regex 'java-1.8.0-openjdk-devel'
This is my first attempt in creating a docker image. Please suggest what is wrong with above Dockerfile. I am working on centos7.
Another approach is that you can build your Dockerfile based on FROM ubuntu:20.04 where Python 3.8 is set as default (here). Then, install java and pip later.
FROM ubuntu:20.04
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN apt-get update -y \
&& apt-get install -y software-properties-common \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt-get install openjdk-8-jdk -y \
&& apt-get install python3-pip -y \
&& export JAVA_HOME \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Why Java is not getting installed in my docker image using Postgres docker hub image

What I would like is to add Java (installation and JAVA_HOME) in an image.
I'm using this postgres dockerfile: https://github.com/docker-library/postgres/tree/master/9.6
Which I updated with the following :
RUN apt-get -y update
RUN apt-get -y install wget
RUN apt-get -y install sudo
RUN /bin/mkdir /usr/lib/jvm
RUN wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz -O /tmp/openjdk-11.0.2_linux-x64_bin.tar.gz
RUN sudo tar xfvz /tmp/openjdk-11.0.2_linux-x64_bin.tar.gz --directory /usr/lib/jvm
RUN rm -f /tmp/openjdk-11.0.2_linux-x64_bin.tar.gz
ENV JAVA_HOME /etc/alternatives/jre
Please note that I'm beginner so if something is obvious for you it may not be for me.
The issue is that, /usr/lib/jvm is not created thus java is not installed and also JAVA_HOME is empty when I run the image.
When I execute manually the instructions, it works, but I would like to make my dockerfile working.

How to cut size of python in Debian Java based Docker image?

I am trying to reduce the size of my Docker image, it has to have both python for aws-cli utilities and java for local testing using local-dynamodb. I have tried using alpine image with openjdk, but because it uses musl instead of glibc it does not work.
My image is currently 870 MB, most of it would the python3 package I install using apt-get.
What can I do to cut down it's size? Is there any way to get 'slim' version like the ones that are preinstalled on alpine/debian?
Here's my Dockerfile:
FROM openjdk:8u222-jre-slim-buster
RUN apt-get update && apt-get -y install curl gnupg2 && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" |
tee /etc/apt/sources.list.d/yarn.list && \
apt update && apt-get install -y \
groff \
jq \
nodejs \
less \
yarn \
python3-dev \
python3-pip && \
pip3 install --upgrade pip awscli boto3 aws-sam-cli
You can find slimmed versions docker python images on dockerhub https://hub.docker.com/_/python
However, I would advise to first get more info on what is taking up space in your image: Don't try to optimise what you haven't measured.
In this case, and from personal experience, I would think that the Java part is what's taking up space.
You can also cleanup apt-get after you're done, using something like
apt-get remove --purge ${builds_deps} -y
apt-get clean
rm -rf -- /var/lib/apt/lists/*

Create Docker container with both Java and Node.js

I am not sure why I expected this to work:
# Dockerfile
FROM node:6
FROM java:8
but it doesn't really work - looks like the first command is ignored, and second command works.
Is there a straightforward way to install both Node.js and Java in a Docker container?
Ultimately the problem I am trying to solve is that I am getting an ENOENT error when running Selenium Webdriver -
[20:38:50] W/start - Selenium Standalone server encountered an error: Error: spawn java ENOENT
And right now I assume it's because Java is not installed in the container.
The best way for you is to take java (which is officially deprecated and it suggests you use openjdk image) and install node in it.
So, start with
FROM openjdk:latest
This will use the latest openjdk image, which is 8u151 at this time. Then install node and other dependencies you might need:
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
You might want to install things like grunt afterwards, so this might come in handy as well.
RUN npm install -g grunt grunt-cli
In total you will get the following Dockerfile:
FROM openjdk:latest
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh \
RUN npm install -g grunt grunt-cli
You may clone the Dockerfile from my gitlab repo here
You can use single FROM per generated image.
Try to use node as a base image and install java to it.
Dockerfile
FROM node:latest
RUN apt-get -y install default-jre
You can choose the version you need:
apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
You can also use the node image and then install the default-jre:
# Dockerfile
FROM node:latest
RUN apt-get -y install default-jre
You can choose the version you need:
apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
Perhaps, you might want to try this https://hub.docker.com/r/timbru31/java-node one to create the docker file.
This docker image comes with both Java and Node pre-installed. It comes in handy when both are required as a dependency.
Something like,
FROM timbru31/java-node:<tag>
The FROM inside your dockerfile simply tells docker from which image it should start the configuration. You can't simply concatenate multiple images together. There are already multiple container images available which offer preinstalled Java 8 and node JS. I don't want to recommend any image specifically but will direct you to docker-hub for you to go search on your own and use the container that suites your needs the best.
With version 14 of node it works perfectly for me:
FROM openjdk:latest
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh \
RUN npm install -g grunt grunt-cli
this worked for me:
FROM openjdk:16-slim-buster
RUN apt-get update; apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
This works for me with node v16.15.0, be careful with the packages version of java, I'm using the latest by default. The packages used for java are:
Java Runtime Environment (jre)
Java Development Kit (jdk)
FROM node:16.15.0
RUN apt-get update \
&& apt-get install default-jre -y \
&& apt-get install default-jdk -y
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
RUN npm install --global nodemon
COPY . .
EXPOSE 3000
CMD ["npm", "run", "dev"]
I hope this works for you all

Categories

Resources