Split JDK and create a Corretto-JRE for runtime
marcellodesales opened this issue ยท 9 comments
In addition to the JDK, used to BUILD an application, you guys should provide a JRE version for only the RUNTIME.
Users can use the image using a Multi-stage build. That way, the Runtime image should be much smaller.
- Other reasons include security (not exposing javac to runtime systems)
Here is how the Dockerfile could look like:
FROM maven:3.6-amazoncorretto-8 as BUILD
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN mvn -s /usr/share/maven/ref/settings-docker.xml package
FROM amazoncorretto:8-jre
EXPOSE 8080 5005
COPY --from=BUILD /usr/src/app/target /opt/target
WORKDIR /opt/target
ENV _JAVA_OPTIONS '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
CMD ["java", "-jar", "greeting.war"]
Here is the Dockerfile which can be used to create JRE distribution
FROM amazonlinux:2
# install amazon corretto-8 (JRE)
RUN /usr/bin/amazon-linux-extras enable corretto8
RUN /usr/bin/amazon-linux-extras install -y corretto8
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre
also please create a headless version. There is so much unnused stuff in that image. Also already coming from amazonlinux:2 ...
@Hades32 Slimming down our Docker images is something we are looking at doing.
@davecurrie what is the plan for jre based container? It would be great to publish (and manage the upgrades) so that people can us it.
@zaknuces They are planned although I can't share more info at this time.
They are planned although I can't share more info at this time.
Here are all some common images that one might use for JDK 8 (with AL2 thrown in for comparison) sorted by size:
repo | tag | created | size | base |
---|---|---|---|---|
openjdk | 8-jre-alpine | 5 months ago | 84.9MB | alpine3.9 |
openjdk | 8-alpine | 5 months ago | 105MB | alpine:3.9 |
adoptopenjdk/openjdk8 | alpine-jre | 36 hours ago | 122MB | alpine:3.10 |
amazonlinux | 2 | 6 weeks ago | 163MB | amazonlinux:2 |
openjdk | 8-jre-slim | 44 hours ago | 184MB | debian:buster-slim |
adoptopenjdk/openjdk8 | slim | 37 hours ago | 189MB | ubuntu:18.04 |
adoptopenjdk/openjdk8 | jre | 6 weeks ago | 200MB | ubuntu:18.04 |
adoptopenjdk/openjdk8 | alpine | 37 hours ago | 222MB | alpine:3.10 |
openjdk | 8-jre | 44 hours ago | 246MB | buildpack-deps:stretch-curl |
openjdk | 8-slim | 44 hours ago | 284MB | debian:buster-slim |
adoptopenjdk/openjdk8 | latest | 3 weeks ago | 305MB | ubuntu:18.04 |
amazoncorretto | 8 | 3 days ago | 390MB | amazonlinux:2 |
openjdk | 8 | 44 hours ago | 488MB | buildpack-deps:stretch-scm |
amazoncorretto:8
is the second largest.
Nearly all of the increase from the 163MB amazonlinux:2
image to the 390MB amazoncorretto:8
image is in the /usr/lib/jvm
directory:
I had been using @GopinathMR's suggestion about installing just the JRE on top of Amazon Linux 2 docker image (image jre-github
.) I'm not sure if over time the Corretto image has gotten smaller, or that method of install has gotten larger. Here are the current results. At this point, it seems like the best course of action is just to use the official image. A new JRE only image would be appreciated though!
REPOSITORY TAG IMAGE ID CREATED SIZE
jre-github latest 81f71de31f57 3 seconds ago 567MB
jre latest 572c1aa93618 4 minutes ago 416MB
amazoncorretto 8u232 5dc6819f98d7 18 hours ago 390MB
amazonlinux 2 6ef285e58e33 18 hours ago 163MB
(my Dockerfile for the "jre" image trying to squash layers.)
FROM amazonlinux:2
# install amazon corretto 8 JRE
RUN yum update -y && \
amazon-linux-extras enable corretto8 && \
amazon-linux-extras install -y corretto8 && \
yum clean all
Is there any update on availability of jre only images for corretto ?