pg_dump, perl and bin/sh bin/env on distroless

93 views
Skip to first unread message

Gergely Brautigam

unread,
Sep 16, 2024, 3:02:20 PM9/16/24
to Distroless Users
Hello peeps.

I need an end image that has pg_dump on it that works. For it to work, it needs perl and sh and env because pg_dump uses those and the respective libraries.

I would like to do something like a builder image, install perl and posgtresql_client and then copy over the necessary things, but so far, no luck.

Something was always missing, or /bin/sh or /bin/env just said, not found. Even though I copied those over,  but most likely I can't just do that... 

# Use the official Golang image to create a build artifact.
FROM golang:1.23 as builder

# Set the Current Working Directory inside the container
WORKDIR /go/src/app
COPY . .

RUN go mod download

RUN CGO_ENABLED=0 go build -o /go/bin/app

# Install pg_dump by installing postgresql-client
RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client perl

# Start a new stage from scratch
FROM gcr.io/distroless/static-debian11:debug

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /go/bin/app /
COPY --from=builder /go/src/app/local_manifest.yaml /
# Copy the pg_dump binary and necessary libraries from the first stage
COPY --from=builder /usr/bin/pg_dump /
COPY --from=builder /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
COPY --from=builder /lib/x86_64-linux-gnu /lib/x86_64-linux-gnu
COPY --from=builder /usr/bin/perl /usr/bin/perl

# Debug
COPY --from=builder /bin/sh /bin/sh
COPY --from=builder /bin/env /bin/env

# Expose port 8080 to the outside world
EXPOSE 8080

# Command to run the executable
ENTRYPOINT ["/app"]

This is the docker file I'm trying to achieve things with. Obviously not ideal.

I'm also looking for info if this is just not sustainable and I should rather go for something like debian:bookworm-slim or something at that point since I already put sh and env into the image anyways.

Thanks
Gergely.
Reply all
Reply to author
Forward
0 new messages