简体   繁体   中英

how to build docker image that are using java11

I am working with Spring boot. The following Dockerfile and run.sh is working fine and the docker image is built using the docker-plugin in build.gradle.

Now I want to make a docker image of an application that uses some functions of Java11. So, If I made a docker image from the following Dockerfile. How could I do so? So, that Java11 functions could be accessible with the docker image.

build.gradle

task buildDocker(type: Docker, dependsOn: build) {
    push = false
    applicationName = jar.baseName
    dockerfile = file('src/main/docker/Dockerfile')
    doFirst {
        copy {
            from jar
            into stageDir
        }
        copy {
            from "${project.buildDir}/resources/main/run.sh"
            into stageDir
        }
    }

Dockerfile

FROM openjdk:8u121-jdk-alpine

# Keep consistent with build.gradle
ENV APP_JAR_NAME pineCharts

# Install curl
RUN apk --update add curl bash && \
    rm -rf /var/cache/apk/*

RUN mkdir /app

ADD ${APP_JAR_NAME}.jar /app/
ADD run.sh /app/
RUN chmod +x /app/run.sh

WORKDIR /app

EXPOSE 8082

ENTRYPOINT ["/bin/bash","-c"]
CMD ["/app/run.sh"]

run.sh

#!/usr/bin/env bash
java -Djava.security.egd=file:/dev/urandom -Dspring.profiles.active=${SPRING_ACTIVE_PROFILE} -Dgit.config.active.branch=${GIT_BRANCH_LABEL} -Duser.timezone=Asia/Kolkata -XX:+PrintFlagsFinal $JAVA_OPTIONS -jar ${APP_JAR_NAME}.jar

Here is an example

FROM adoptopenjdk/openjdk11:latest

RUN mkdir -p /software/app

ADD target/app.jar /software/app/app.jar

ENV port=8888

CMD java -jar /software/app/app.jar -Dspring.profiles.active=${SPRING_ACTIVE_PROFILE}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM