Skip to content

Commit cb88c09

Browse files
committed
templates/jlink/Dockerfile: only microdnf, non-root user
microdnf (since at least 9.1-3.el9) now supports the required flags to install packages in a different root, therefore we do not need to install dnf in the first phase. remove the 'dnf clean all' which was operating in the wrong context. Clear up some cache directories inherited from ubi-micro. Remember to switch the runtime user away from root! Signed-off-by: Jonathan Dowland <[email protected]>
1 parent a11fcef commit cb88c09

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

templates/jlink/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
FROM ubi9-jlinked-image AS ubi9-jlinked-image
66
USER 0
77
RUN mkdir -p /mnt/jrootfs
8-
RUN microdnf install dnf -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs
9-
RUN dnf install --installroot /mnt/jrootfs --releasever 9 --setopt install_weak_deps=false --nodocs -y \
10-
grep gawk \
11-
&& dnf clean all
12-
RUN rm -rf /mnt/jrootfs/var/cache/* /mnt/jrootfs/var/lib/rpm
8+
RUN microdnf install --installroot /mnt/jrootfs --releasever 9 --setopt install_weak_deps=0 --nodocs -y \
9+
--config=/etc/dnf/dnf.conf \
10+
--noplugins \
11+
--setopt=cachedir=/var/cache \
12+
--setopt=reposdir=/etc/yum.repos.d \
13+
--setopt=varsdir=/etc/dnf/vars \
14+
grep gawk
15+
RUN rm -rf /mnt/jrootfs/var/cache/* /mnt/jrootfs/var/lib/rpm /mnt/jrootfs/var/lib/dnf
1316

1417
#Stage-2:copy application JAR and jlinked JRE to runtime image
1518
FROM registry.access.redhat.com/ubi9/ubi-micro AS lean-runtime
@@ -19,6 +22,9 @@ COPY --from=ubi9-jlinked-image /mnt/jrootfs/ /
1922
COPY --from=ubi9-jlinked-image /deployments /deployments
2023
COPY --from=ubi9-jlinked-image /tmp/jre ${JAVA_HOME}
2124
COPY --from=ubi9-jlinked-image /opt/jboss/container/ /opt/jboss/container/
25+
# these are in the micro image
26+
RUN rm -rf /var/lib/dnf /var/lib/rpm
2227

2328
ENV JAVA_HOME="${JAVA_HOME}" PATH="${JAVA_HOME}/bin:$PATH"
29+
USER 185
2430
CMD /opt/jboss/container/java/run/run-java.sh

0 commit comments

Comments
 (0)