Installing Java8 in Dockerfile [duplicate] - java

I am trying to install java 8 through oracle-java8-installer on a debian:jessie docker container. The following is my Dockerfile:
FROM debian:jessie
ENV JAVA_VERSION 1.8.0
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" > /etc/apt/sources.list.d/webupd8team-java.list
RUN echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" >> /etc/apt/sources.list.d/webupd8team-java.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
RUN echo "debconf shared/accepted-oracle-license-v1-1 select true" | /usr/bin/debconf-set-selections
RUN apt-get update
RUN apt-get install -y --force-yes vim
RUN apt-get install -y --force-yes oracle-java8-installer
Yet this gives:
Connecting to download.oracle.com (download.oracle.com)|23.63.224.171|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-01-17 12:31:05 ERROR 404: Not Found.
download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
oracle-java8-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt-get install -y --force-yes oracle-java8-installer' returned a non-zero code: 100
I have found many similar issues described online, but none of the proposed solutions worked for me. Any idea?

Found the solution on https://hub.docker.com/r/anapsix/docker-oracle-java8/~/dockerfile/:
## JAVA INSTALLATION
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" > /etc/apt/sources.list.d/webupd8team-java-trusty.list
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes --no-install-recommends oracle-java8-installer && apt-get clean all
The "secret sauce" you were looking for is the first line:
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections

Re to donhector's response and your question: you need to replace the strings in the installer file, instead of yours last command:
apt-get install -y --force-yes oracle-java8-installer
run these commands:
apt-get -y install oracle-java8-installer || true
cd /var/lib/dpkg/info
sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' oracle-java8-installer.*
sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' oracle-java8-installer.*
sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' oracle-java8-installer.*
sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' oracle-java8-installer.*
apt-get install -f -y
apt-get install -y oracle-java8-set-default
I have them in a separate script and run it as
RUN /bin/sh /path/to/script.sh
or you can run them directly from your Dockerfile, that's up to you.

You are installing from the webupd8 PPA repo. If you notice, the Java 8 package in that repo points to Java 8 version 151. That package pulls the binary for 151 from the Oracle servers (since Java Oracle licence does not allow anyone else hosting the binaries). Oracle released version 161 a couple days back and apparently moved or removed 151 from their servers. So basically the package in the webupd8 PPA repo is trying to download the 151 binary which no longer exists at the location that the webupd8 package expects it (hence the 404 you got). The webupd8 PPA repo maintainer will have to release a new package pointing to the new 161 binaries from Oracle. Docker or Debian don't play any role in the issue, it is just basically a broken link issue.
Until then you could apply a "workaround" like the one mentioned here: JDK 8 is NOT installed - ERROR 404: Not Found
Here's the list of Java packages in the webupd8 repo:
https://launchpad.net/~webupd8team/+archive/ubuntu/java/+packages

See dpkg oracle Jdk error while installing cassandra in Ubuntu 16.04. This issue is occurring for everyone using install scripts of any kind.

** Java 11:
RUN apt-get install wget java-common gnupg2 -y
RUN echo "oracle-java11-installer shared/accepted-oracle-license-v1-2 select true" | debconf-set-selections
RUN echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | tee /etc/apt/sources.list.d/linuxuprising-java.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends oracle-java11-installer && apt-get clean all

Related

Unable to run Java on Dockerfile since yesterday

I have a set up of Protractor, for which I need java in my Dockerfile to run the selenium-server.jar file.
Here is my Dockerfile
FROM node:latest
ENV CHROME_VERSION "google-chrome-stable"
RUN sed -i -- 's&deb http://deb.debian.org/debian jessie-updates main&#deb http://deb.debian.org/debian jessie-updates main&g' /etc/apt/sources.list \
&& apt-get -o Acquire::Check-Valid-Until=false update && apt-get -o Acquire::Check-Valid-Until=false install wget -y
ENV CHROME_VERSION "google-chrome-stable"
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list \
&& apt-get -o Acquire::Check-Valid-Until=false update && apt-get -qqy --allow-unauthenticated install ${CHROME_VERSION:-google-chrome-stable}
# Add the dependencies to get the xenial apt sources
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
RUN echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
RUN apt-get -y update
# Add these silent accept - since oracle installer asks for permission to install java-version-8
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 seen true" | debconf-set-selections
# Install java-8
RUN apt install -y oracle-java8-installer && apt install oracle-java8-set-default
This set up was working fine until yesterday but since then I've been getting this error
download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
oracle-java8-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt install -y oracle-java8-installer && apt install oracle-java8-set-default' returned a non-zero code: 100
Now before marking this question as a duplicate , please see that I have gone through a lot of similar SO posts and applied all the changes mentioned but the error still persists or I get a new error, which circles back to this unable to download error.
I have tried the solutions mentioned in this, this, this and this, this, this, this but haven't been able to solve it.
The complete log file is here. If required, I can post the error that I got when trying to apply the solutions mentioned.
Looking for any pointers to solve this issue.
Do you really need to have oracle jdk? In the pass, I used the content of Dockerfile from openjdk to build an image from node and having java installed: https://github.com/docker-library/openjdk/blob/master/8/jdk/Dockerfile
Nevertheless, in your case, I would build a centralized selenium server or use a directConnect in CI pipeline.
Docker will remember the result of running each command unless you explicitly tell it not to (docker build --no-cache). In particular, it will skip over running the apt-get update step if it thinks it’s already done this.
Meanwhile, the Debian and Ubuntu repositories update frequently, and when they update, they remove old versions of packages. This means that if you’re using yesterday’s version of the package cache, you’ll get “download failed” errors like you see until you re-run apt-get update.
In a Docker context, the correct answer to this is to always run apt-get update and apt-get install in the same RUN step. You might change the end of your Dockerfile to look like
RUN apt-get update -y \
&& apt install oracle-java8-installer oracle-java8-set-default
Once you’ve gotten past the initial development stage it’s probably good practice to just have a single apt install command in your Dockerfile that does one pass at installing all of the runtime dependencies you need.

Docker phusion/baseimage install oracle_db

Can someone help me install oracle_db client on my existing docker image. I tried so hard to get around a fix for this issue. Looks impossible to install oracle_db with phusion/baseimage.
My dockerfile is this:
FROM phusion/baseimage
MAINTAINER bugsbunny
RUN echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list
RUN add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe"
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q python-software-properties software-properties-common
ENV JAVA_VER 8
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
RUN echo 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main' >> /etc/apt/sources.list && \
echo 'deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main' >> /etc/apt/sources.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C2518248EEA14886 && \
apt-get update && \
echo oracle-java${JAVA_VER}-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
apt-get install -y --force-yes --no-install-recommends oracle-java${JAVA_VER}-installer oracle-java${JAVA_VER}-set-default && \
apt-get clean && \
rm -rf /var/cache/oracle-jdk${JAVA_VER}-installer
RUN update-java-alternatives -s java-8-oracle
RUN echo "export JAVA_HOME=/usr/lib/jvm/java-8-oracle" >> ~/.bashrc
RUN apt-get install nano
RUN apt-get install -y ksh
RUN echo "deb http://cz.archive.ubuntu.com/ubuntu trusty main" > /etc/apt/sources.list
RUN apt-get update
RUN cd /home/ && wget http://launchpadlibrarian.net/333072908/libaio1_0.3.110-4_amd64.deb && dpkg -i libaio1_0.3.110-4_amd64.deb
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD mtf-release /home/mtf-release
ADD instantclient_12_2 /opt/oracle/instantclient_12_2
RUN sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf" && ldconfig
RUN export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH
RUN mkdir -p /opt/oracle/instantclient_12_2/network/admin
RUN export PATH=/opt/oracle/instantclient_12_2:$PATH
#ENTRYPOINT ["/usr/bin/python"]
As you can see, I need java:8 version and oracle_db client, sqlplus to make my docker work. Is there any proper docker image which has java + oracledb or anyway to merge two docker images into one so that I have both installed working fine.? Thank you.
Can someone help me with using two FROMs and what all images i need?
So you want a Docker image that container both oracle client and java.
Oracle provides a Docker image for the instant client and the source code for the Docker file can be found here.
For Java there are many Docker images available such as openjdk.
You can merge the two images using Docker multi-stage builds. Before that make sure to login into docker store, go to oracle instantclient image, and accept the license and pull the image docker pull store/oracle/database-instantclient:12.2.0.1
FROM store/oracle/database-instantclient:12.2.0.1 as oracle
FROM openjdk:8-jdk
COPY --from=oracle /usr/lib/oracle /usr/lib/oracle
ENV PATH=$PATH:/usr/lib/oracle/12.2/client64/bin
Once you build the above dockerfile you will have a docker image containing java and oracle instantclient.

Install java 8 (jdk 1.8) using "vagrant up" not working on debian

When I am Running My Vagrantfile with its shell, I'm struggle with Java 8 install with this exact same error :
StackOverflow - jdk-8-is-not-installed-error-404-not-found
In order to fix that error, I added those lines :
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*
I have in my Shell this block for java section:
# /*======================
# = JAVA =
# ======================*/
# https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-debian-8
sudo apt-get install -y software-properties-common
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
sudo apt-get update
# Silent !! Sshh !
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
# see https://stackoverflow.com/questions/46815897/jdk-8-is-not-installed-error-404-not-found
# Still not work
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo apt-get install -y oracle-java8-installer
sudo apt-get install -y oracle-java8-set-default
The weird thing is : Those lines taken one by one via SSH when the box is started and you can install Java, it Works. But it's not working when I provision for the first time my vagrant box.
Is the problem comes from sed or another command ? I suppose it's the sed's command but don't know how to fix it, because it's working if I paste them via SSH.
I want to make this work without any manual interventions.
You can test my VM using this github repo (V2) :
VagrantFile + shells
How can I make this work using vagrant up ?
EDIT :
I've tested it on Vagrant 2.0 and virtualBox 5.6
Also tested with vagrant 1.7 and virtualBox 5.1
I'm putting this in just in case anyone is fine with Debians basic version, but has missed it. I think it should already be installed on anything but the most bare-bones systems.
To get openJDK working, which is the version offered in Debians standard repos, you would just need to use
apt-get install -y openjdk-8-jdk
There are other debug and docs packages as well.
Debian also provide a package in the contrib repos called java-package which converts the source tarball from the Oracle site (you have to get it yourself to OK the terms and conditions), and creates a deb from it. Unfortunately there doesn't seem to be a way to directly presume yes to the questions asked, so it would need an expect script or something.
config.vm.provision "shell", inline: <<-SHELL
# add contrib repos into source files.
mv /etc/apt/sources.list /etc/apt/sources.bk
sed -r ‘s/stretch([^ ]*) main$/& contrib/‘ /etc/apt/sources.bk | sudo tee /etc/apt/sources.list
# vi -c ':%s/stretch\([^ ]*\) main$/& contrib/g' /etc/apt/sources.list -c 'wq'
apt-get update
apt-get install -y java-package java-common expect
# some `expect` needed magic here
sudo -u vagrant fakeroot make-jpkg /vagrant/jdk-8*
dpkg -i oracle-java8*
SHELL
In terms of the interactions I get using make-jpkg, this script works (from the command line)
expect -c '
set timeout -1
spawn fakeroot make-jpkg /vagrant/jdk-8u162-linux-x64.tar.gz
expect "Is this correct \\\[Y/n\\\]: $" { send "Y\r" }
expect "Press \\\[Return\\\] to continue: " { send "\r" }
expect "*Press \\\[Return\\\] to continue or Ctrl-C to abort." { send "\r" }
expect eof { exit 0 }
'
but could probably be done other ways.
So almost an answer, but may get you a bit closer.
Sorry for my late answer. Another option is to mount a drive and install the oracle rpm package silently.
Create directory and put there your Vagrantfile. This the root of your project. (./)
Vagrantfile
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "bento/centos-7.4"
config.vm.boot_timeout = 240
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# View the documentation for the provider you are using for more
# information on available options.
config.vm.provider "virtualbox" do |vb|
# Enable the Host I/O cache for more performance
vb.customize [
"storagectl", :id,
"--name", "SATA Controller",
"--hostiocache", "on"
]
vb.auto_nat_dns_proxy = false
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"
vb.customize ["modifyvm", :id, "--memory", 4096]
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.cpus = 4
end
# Synced folders are configured within your Vagrantfile using the config.vm.synced_folder method.
# Vagrant shares by default the root directory of (./) with guest on /vagrant
config.vm.synced_folder ".", "/vagrant", disabled: true
# Synced folder is set as read-only for guest machine. You can configure the files on the host machine.
# For more mount options check: http://manpages.ubuntu.com/manpages/precise/man8/mount.vboxsf.8.html
config.vm.synced_folder "./installfiles", "/installfiles",
owner: "vagrant", group: "vagrant", mount_options: ["ro"]
# Bootstrap shell scripts.
config.vm.provision "shell", path: "./bootstrap/setup.sh"
config.vm.post_up_message = "Finsihed provisioning!\n" \
"Type \"vagrant ssh\" to get started"
end
Create another directory named bootstrap from the root of your project. Create an empty file called setup.sh, put the content below in the setup.sh file. The file path will be ./bootstrap/setup.sh
setup.sh
#!/usr/bin/env bash
echo "installing Java 8 64 bit"
sudo rpm -i /installfiles/java8/jdk-8u144-linux-x64.rpm
unzip /installfiles/java8/jce_policy-8.zip -d /tmp
sudo cp -f /tmp/UnlimitedJCEPolicyJDK8/* $JAVA_HOME/lib/security/
Go to the oracle website download the correct 32 or 64 bit rpm linux package. Versions available on the oracle website might change. For this example i downloaded the jdk-8u144-linux-x64.rpm package. I also downloaded the unlimited encryption strength policy from the oracle website, name of the file is: jce_policy-8.zip.
Create two directories from the root of your project named installfiles/java8. Place the downloaded files in there. The files path will be: ./installfiles/java8/jdk-8u144-linux-x64.rpm and ./installfiles/java8/jce_policy-8.zip
Run the command vagrant up. On your host machine the directory ./installfiles will be synchronised with your virtualbox guest machine on the path /installfiles. During the provisioning state of vagrant java-8 will be installed automatically. Keep in mind that the rpm package manager comes out of the box with Red Hat distros. But it is also possible to install rpm packages on debian distros.
The following snippet fixes the silent install of java from webupd8team repo for Debian distribution
sudo apt-get -y install software-properties-common
sudo add-apt-repository -y ppa:webupd8team/java
sudo bash -c "echo deb http://http.debian.net/debian jessie-backports main >> /etc/apt/sources.list"
sudo bash -c "echo deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo bash -c "echo deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
sudo apt-get -y upgrade
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selectionssudo
sudo apt-get -y install oracle-java8-installer oracle-java8-set-default
As of today, it installs the following
vagrant#debian-8:~$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

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

How to set java-7-oracle as default java version?

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
I tried to install oracle-java7 on my Linux Mint with the codes above. After executing those codes, I tried to check if its working by typing "java -version" but suddenly an error occured.
bash: /usr/bin/java: cannot execute binary file: Exec format error
You can install a package to set (and keep) oracle-java7 as the default; or you can manually set the java alternative with update-java-alternatives. Something like,
Option 1. sudo apt-get install oracle-java7-set-default
Option 2. sudo update-java-alternatives -s java-7-oracle

Categories

Resources