Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How install java to ubuntu on docker?

I tried use docker. I install tool docker and run. I dovnload ubuntu image and run on docker. I make all by this link

For install ubuntu I used docker run -it ubuntu bash

After that I run this ubuntu docker run -i -t ubuntu:latest /bin/bash

After start I placed root@9bca9a2a537d:/#

Now I want install java and start some app on this java.

I tried install java root@cf50a6fdfc10:/# apt-get install default-jre

When this installed i try run this command java -version and I see

root@2e62f448f783:/# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

after that i exit from ubuntu

root@2e62f448f783:/# exit

and run again. And when ubuntu started i try

root@20cefe55e2eb:/# java -version
bash: java: command not found

How can I install java or start this java version?

like image 210
user5620472 Avatar asked Jul 21 '16 05:07

user5620472


2 Answers

As paulscott56 said, you can add those lines in your Dockerfile:

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive \
    apt-get -y install default-jre-headless && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

https://hub.docker.com/r/pataquets/default-jre-headless/~/dockerfile/

like image 132
Gautier Avatar answered Oct 12 '22 23:10

Gautier


The container is a single contained entity. All changes that you make to it are essentially lost when you quit and restart it. There are 2 solutions to his though:

  1. Do it properly, and add java to a RUN apt-get line in your Dockerfile, OR
  2. (Bad bad bad) Add it and hope your host never goes down.

Depending on what you want (Ubuntu or a container to run a Java app), you should either use the method in 1. or create a new Dockerfile that grabs FROM Java8 base image.

like image 23
paulscott56 Avatar answered Oct 13 '22 00:10

paulscott56