Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put Java onto a Ubuntu docker container?

Tags:

java

docker

I currently have a docker container with an Ubuntu(17.10) image installed with other packages included. However, I'm currently having difficulty trying to install Java onto this container in addition to the current image.

Current Dockerfile :

FROM cityofzion/neo-privatenet
ADD files/ files/
ENTRYPOINT [ "/bin/bash" ]

When trying to find information on how to do this and testing inside of the container most suggest using this command: apt-get install -y oracle-java9-installer

However this results in:E: Unable to locate package oracle-java9-installer

I have also tried this suggested command wget http://download.java.net/java/GA/jdk9/9/binaries/jdk-9+181_linux-x64_bin.tar.gz

Which produces this result HTTP request sent, awaiting response... 404 Not Found - ERROR 404: Not Found.

I have only tried running these commands in the container, since that is how they would be run and they seem to be failing.

Can anyone suggest what I can include into my Dockerfile that install java onto my image?

Thanks in advance.

like image 931
user1522263 Avatar asked Apr 10 '18 00:04

user1522263


People also ask

Can I use Java in Docker?

You can use Docker to run a Java application in a container with a specific runtime environment. This tutorial describes how to create a Dockerfile for running a simple Java application in a container with OpenJDK 17. It also shows how to create a Docker image with your application to share it with others.

Does Docker need JDK?

Use a JRE, not a JDK When creating a Docker image, we should only assign the necessary resources to function correctly. This means that we should start by using an appropriate Java Runtime Environment (JRE) for your production image and not the complete Java Development Kit (JDK).

What is a Java Docker container?

Intro to managing and running a containerized Java Spring Boot application. Docker is a platform for packaging, deploying, and running applications in containers. It can run containers on any system that supports the platform: a developer's laptop, systems on “on-prem,” or in the cloud without modification.


1 Answers

You can also directly pull any of the open-jdk images mentioned at (https://hub.docker.com/_/openjdk/) and use it. There is no need to install Ubuntu in docker image and then install Java on top of it. These images already use Ubuntu (with bare-minimum file system).

like image 127
Harsh Mehta Avatar answered Oct 23 '22 09:10

Harsh Mehta