0

My goal is to create an image using the FROM scratch. However, I need pdftotext. Hence, I need to install poppler-utils on FROM alpine:3.16. Then, copy it to FROM scratch stage.

My concern is that:

  1. someone said that there are layers limit of 42. This reproducible code already uses 22.

What I am thinking to do:

  1. multi-stage build.
FROM alpine:3.16

RUN apk add poppler-utils

FROM scratch

(...tons of COPY --from=0)

FROM scratch

COPY --from=1 . .
  1. or RUN --mount
FROM alpine:3.16

RUN apk add poppler-utils

FROM scratch

RUN --mount=src=/,dst=/,from=0 \
  (...tons of cp)

This is the current solution that I use.

Dockerfile

FROM alpine:3.16

RUN apk add poppler-utils

FROM scratch

WORKDIR /

COPY --from=0 /lib/ld-musl-aarch64.so.1 /lib/ld-musl-aarch64.so.1
COPY --from=0 /usr/lib/libpoppler.so.121 /usr/lib/libpoppler.so.121
COPY --from=0 /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6
COPY --from=0 /lib/ld-musl-aarch64.so.1 /lib/ld-musl-aarch64.so.1
COPY --from=0 /usr/lib/libfreetype.so.6 /usr/lib/libfreetype.so.6
COPY --from=0 /usr/lib/libfontconfig.so.1 /usr/lib/libfontconfig.so.1
COPY --from=0 /usr/lib/libjpeg.so.8 /usr/lib/libjpeg.so.8
COPY --from=0 /lib/libz.so.1 /lib/libz.so.1
COPY --from=0 /usr/lib/libopenjp2.so.7 /usr/lib/libopenjp2.so.7
COPY --from=0 /usr/lib/liblcms2.so.2 /usr/lib/liblcms2.so.2
COPY --from=0 /usr/lib/libpng16.so.16 /usr/lib/libpng16.so.16
COPY --from=0 /usr/lib/libtiff.so.5 /usr/lib/libtiff.so.5
COPY --from=0 /usr/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1
COPY --from=0 /usr/lib/libbz2.so.1 /usr/lib/libbz2.so.1
COPY --from=0 /usr/lib/libbrotlidec.so.1 /usr/lib/libbrotlidec.so.1
COPY --from=0 /usr/lib/libexpat.so.1 /usr/lib/libexpat.so.1
COPY --from=0 /usr/lib/libwebp.so.7 /usr/lib/libwebp.so.7
COPY --from=0 /usr/lib/libzstd.so.1 /usr/lib/libzstd.so.1
COPY --from=0 /usr/lib/liblzma.so.5 /usr/lib/liblzma.so.5
COPY --from=0 /usr/lib/libbrotlicommon.so.1 /usr/lib/libbrotlicommon.so.1
COPY --from=0 /usr/bin/pdftotext /usr/bin/pdftotext

Output from $ docker build -t test .

[+] Building 0.5s (27/27) FINISHED                                              
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 2.04kB                                     0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/alpine:3.16             0.0s
 => [stage-0 1/2] FROM docker.io/library/alpine:3.16                       0.0s
 => CACHED [stage-0 2/2] RUN apk add poppler-utils                         0.0s
 => [stage-1  1/22] COPY --from=0       /lib/ld-musl-aarch64.so.1 /lib/ld  0.0s
 => [stage-1  2/22] COPY --from=0       /usr/lib/libpoppler.so.121 /usr/l  0.0s
 => [stage-1  3/22] COPY --from=0       /usr/lib/libstdc++.so.6 /usr/lib/  0.0s
 => [stage-1  4/22] COPY --from=0       /lib/ld-musl-aarch64.so.1 /lib/ld  0.0s
 => [stage-1  5/22] COPY --from=0       /usr/lib/libfreetype.so.6 /usr/li  0.0s
 => [stage-1  6/22] COPY --from=0       /usr/lib/libfontconfig.so.1 /usr/  0.0s
 => [stage-1  7/22] COPY --from=0       /usr/lib/libjpeg.so.8 /usr/lib/li  0.0s
 => [stage-1  8/22] COPY --from=0       /lib/libz.so.1 /lib/libz.so.1      0.0s
 => [stage-1  9/22] COPY --from=0       /usr/lib/libopenjp2.so.7 /usr/lib  0.0s
 => [stage-1 10/22] COPY --from=0       /usr/lib/liblcms2.so.2 /usr/lib/l  0.0s
 => [stage-1 11/22] COPY --from=0       /usr/lib/libpng16.so.16 /usr/lib/  0.0s
 => [stage-1 12/22] COPY --from=0       /usr/lib/libtiff.so.5 /usr/lib/li  0.0s
 => [stage-1 13/22] COPY --from=0       /usr/lib/libgcc_s.so.1 /usr/lib/l  0.0s
 => [stage-1 14/22] COPY --from=0       /usr/lib/libbz2.so.1 /usr/lib/lib  0.0s
 => [stage-1 15/22] COPY --from=0       /usr/lib/libbrotlidec.so.1 /usr/l  0.0s
 => [stage-1 16/22] COPY --from=0       /usr/lib/libexpat.so.1 /usr/lib/l  0.0s
 => [stage-1 17/22] COPY --from=0       /usr/lib/libwebp.so.7 /usr/lib/li  0.0s
 => [stage-1 18/22] COPY --from=0       /usr/lib/libzstd.so.1 /usr/lib/li  0.0s
 => [stage-1 19/22] COPY --from=0       /usr/lib/liblzma.so.5 /usr/lib/li  0.0s
 => [stage-1 20/22] COPY --from=0       /usr/lib/libbrotlicommon.so.1 /us  0.0s
 => [stage-1 21/22] COPY --from=0 /usr/bin/pdftotext /usr/bin/pdftotext    0.0s
 => exporting to image                                                     0.1s
 => => exporting layers                                                    0.1s
 => => writing image sha256:e427868094aba36fafea50aeca50bad9b70315c651914  0.0s
 => => naming to docker.io/library/test                                    0.0s
Jason Rich Darmawan
  • 1,607
  • 3
  • 14
  • 31
  • 1
    I wonder what you're actually gaining here trying to base your image on scratch rather than just basing it the alpine image. This would dramatically simplify the logic in your Dockerfile, resulting in something that is much more maintainable. I'm not sure the increased complexity of your scratch-based solution is worth the effort. – larsks Sep 18 '22 at 01:08
  • @larsks I believe it reduces the [CVE] (https://github.com/GoogleContainerTools/distroless). – Jason Rich Darmawan Sep 18 '22 at 02:15

0 Answers0