Skip to content

Commit

Permalink
images: Minimize container
Browse files Browse the repository at this point in the history
Use a multi-stage build [1], pick some "small container targetted" basic
packages, and remove some larger packages that we really don't need in
the container. This shrinks the container from 313 to 137 MB.

[1] https://docs.docker.com/develop/develop-images/multistage-build/
  • Loading branch information
martinpitt committed Feb 18, 2021
1 parent 2ef0e26 commit 202904e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
FROM fedora:latest
FROM fedora:latest AS builder
LABEL maintainer='[email protected]'

RUN dnf -y update && \
dnf -y install nginx openssh-server /usr/bin/python && \
dnf clean all && \
mkdir -p /home/user

# avoid unnecessary stuff in the container; systemd is a protected package, so apply some extra force
RUN source /etc/os-release && \
dnf install -y --releasever=$VERSION_ID --setopt=install_weak_deps=False --installroot=/build \
coreutils-single \
glibc-minimal-langpack \
nginx \
openssh-server \
/usr/bin/python3 && \
rpm --root=/build --verbose --erase --nodeps systemd && \
dnf remove -y --installroot=/build systemd-networkd device-mapper dbus-broker cryptsetup && \
rm -r /build/var/cache/dnf /build/var/lib/dnf /build/var/lib/rpm*

FROM scratch
COPY --from=builder /build /

RUN mkdir -p /home/user
# can't use ../sink/sink with docker build
ADD https://raw.githubusercontent.com/cockpit-project/cockpituous/master/sink/sink /home/user/sink

Expand Down

0 comments on commit 202904e

Please sign in to comment.