bxb100 / bxb100.github.io

This is my blog
https://blog.tomcat.run
MIT License
1 stars 0 forks source link

Pick the Right Distroless Base Image For Your Application #46

Open bxb100 opened 5 months ago

bxb100 commented 5 months ago

docker challenge https://labs.iximiuz.com/challenges/pick-the-right-distroless-base-image

image

root@docker-01:~# file server
server: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=016df6500c2c3df1dd3ce82d9e9a5bd547584c97, for GNU/Linux 3.2.0, with debug_info, not stripped
root@docker-01:~# ldd server
        linux-vdso.so.1 (0x00007ffde5df1000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbc097e4000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fbc0a379000)

[!NOTE]

linux-vdso.so.1^1 没有实体文件,文件 GNU/LINUX 编译,那么需要 libc,动态连接 /lib64/ld-linux-x86-64.so.2

FROM scratch

COPY ./server /server
COPY ./libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY ./ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

CMD ["/server"]
FROM golang:alpine as builder
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
RUN update-ca-certificates

FROM scratch

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY ./server /server
COPY ./libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY ./ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

CMD ["/server"]