Repository navigation
Closed
Description
the current image size is around 41MB.
Following this article: https://medium.com/@Gnaphron/minimalist-multi-stage-container-5a62e08b491d
I can get to a 17MB image. Here is the resulting dockerfile:
FROM alpine:latest as builder
COPY . /source/
RUN apk update && apk add --no-cache --virtual .build-dependencies \
cargo \
build-base \
file \
libgcc \
musl-dev \
rust
RUN apk add --no-cache openssl-dev \
llvm-libunwind \
pkgconfig
WORKDIR /source/bin
RUN cargo build --release --features use-openssl
RUN \
mkdir -p /tmp/fakeroot/lib && \
cp $(ldd /source/target/release/sozu | grep -o '/.\+\.so[^ ]*' | sort | uniq) /tmp/fakeroot/lib && \
for lib in /tmp/fakeroot/lib/*; do strip --strip-all $lib; done && \
mkdir /tmp/fakeroot/bin && \
mkdir -p /tmp/fakeroot/run/sozu
FROM scratch AS release
COPY os-build/docker/config.toml /etc/sozu/config.toml
COPY --from=builder /source/target/release/sozu sozu
COPY --from=builder /tmp/fakeroot/ /
ENV SOZU_CONFIG /etc/sozu/config.toml
VOLUME /etc/sozu
VOLUME /run/sozu
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["/sozu"]
CMD ["start", "-c", "/etc/sozu/config.toml"]If I strip the resulting file, I get to 12.5MB:
FROM alpine:latest as builder
COPY . /source/
RUN apk update && apk add --no-cache --virtual .build-dependencies \
cargo \
build-base \
file \
libgcc \
musl-dev \
binutils \
rust
RUN apk add --no-cache openssl-dev \
llvm-libunwind \
pkgconfig
WORKDIR /source/bin
RUN cargo build --release --features use-openssl
RUN strip /source/target/release/sozu
RUN \
mkdir -p /tmp/fakeroot/lib && \
cp $(ldd /source/target/release/sozu | grep -o '/.\+\.so[^ ]*' | sort | uniq) /tmp/fakeroot/lib && \
for lib in /tmp/fakeroot/lib/*; do strip --strip-all $lib; done && \
mkdir /tmp/fakeroot/bin && \
mkdir -p /tmp/fakeroot/run/sozu
FROM scratch AS release
COPY os-build/docker/config.toml /etc/sozu/config.toml
COPY --from=builder /source/target/release/sozu sozu
COPY --from=builder /tmp/fakeroot/ /
ENV SOZU_CONFIG /etc/sozu/config.toml
VOLUME /etc/sozu
VOLUME /run/sozu
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["/sozu"]
CMD ["start", "-c", "/etc/sozu/config.toml"]I'm not sure it's a huge benefit to reduce the size, 41MB already makes a small image, but if it ever becomes a problem, the tricks here can help
Reacted by Theo Paris
Metadata
Metadata
Assignees
Labels
No labels
Activity