Installing java in Docker image

前端 未结 3 2043
夕颜
夕颜 2020-12-24 02:10

This is my very first try to create a docker image and I\'m hoping someone can help me out. My Dockerfile looks roughly like this:

FROM mybaseimage:0.1
MAINT         


        
相关标签:
3条回答
  • 2020-12-24 02:39

    I was able to install OpenJDK-8 via the steps below (taken from here). My Dockerfile inherits from phusion/baseimage-docker, which is based on Ubuntu 16.04 LTS.

    # 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;
    
    # Setup JAVA_HOME -- useful for docker commandline
    ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
    RUN export JAVA_HOME
    

    To install OpenJDK-7 instead, you may need to prepend

    add-apt-repository ppa:openjdk-r/ppa
    

    such that the first step becomes

    # Install OpenJDK-7
    RUN add-apt-repository ppa:openjdk-r/ppa && \
        apt-get update && \
        apt-get install -y openjdk-7-jdk && \
        apt-get install -y ant && \
        apt-get clean;
    

    I hope this helps.

    0 讨论(0)
  • 2020-12-24 02:56

    I was able to install Java-11 on an image using Ubuntu 18.04. I also just needed it for only one application. (The Python wrapper around Apache Tika.)

    FROM python:3.8.2-buster
    COPY . /usr/src/app
    
    # Install OpenJDK-11
    RUN apt-get update && \
        apt-get install -y openjdk-11-jre-headless && \
        apt-get clean;
    
    # Install PYTHON requirements
    COPY requirements.txt ./
    RUN pip install --no-cache-dir -r requirements.txt
    
    # START WEBAPP SERVICE
    CMD [ "python", "/usr/src/app/main.py" ]
    

    Hope that helps.

    0 讨论(0)
  • 2020-12-24 03:01

    There is already an official repo for java, which uses Open JDK.
    Its very easy to use it. Have a look over this repo, which demonstrates very basic hello world program.
    Dockerfile:

    FROM java:7
    COPY src /home/root/java/src
    WORKDIR /home/root/java
    RUN mkdir bin
    RUN javac -d bin src/HelloWorld.java
    ENTRYPOINT ["java", "-cp", "bin", "HelloWorld"]
    

    HelloWorld.java file:

    public class HelloWorld{
        public static void main(String[] args){
            System.out.println("Hello World!!!");
        }
    }
    
    0 讨论(0)
提交回复
热议问题