SLE BCI Documentation
GitHubToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

Deploy an Application using zypper

Scope

The purpose of this guide is to deploy an application or the dependencies of an application from rpms into a deployment image using the zypper package manager.

Using zypper’s custom root

Zypper provides the --installroot flag to install packages into a custom root and not use /. We can leverage this to install packages including all of their dependencies into a custom root and then copy this directory into a deployment image. In the following example we install apache2 including all of its dependencies and copy them into the deployment image based on bci-micro:

FROM registry.suse.com/bci/bci-micro:latest AS micro
FROM registry.suse.com/bci/bci-base:latest AS builder

COPY --from=micro / /chroot/
RUN zypper --installroot /chroot -n --gpg-auto-import-keys in --no-recommends apache2 && \
    zypper --installroot /chroot clean -a && \
    rm -rf /chroot/var/log/

FROM micro
WORKDIR /
COPY --from=builder /chroot/ /

Customizing zypper’s installation behavior

We can further reduce the final image size by supplying a custom zypper configuration file. We can tweak zypper’s behavior further via that configuration file to e.g. omit the installation of documentation files. To achieve this omission of documentation files, create the following scratch-zypp.conf:

[main]
rpm.install.excludedocs = yes

And modify the Dockerfile as follows:

FROM registry.suse.com/bci/bci-micro:latest AS micro
FROM registry.suse.com/bci/bci-base:latest AS builder

COPY --from=micro / /chroot/
COPY scratch-zypp.conf /
ENV ZYPP_CONF=/scratch-zypp.conf
RUN zypper --installroot /chroot -n --gpg-auto-import-keys in --no-recommends apache2 && \
    zypper --installroot /chroot clean -a && \
    rm -rf /chroot/var/log/

FROM micro
WORKDIR /
COPY --from=builder /chroot/ /