Skip to content

Instantly share code, notes, and snippets.

@PThorpe92
Created January 26, 2024 04:16
Show Gist options
  • Save PThorpe92/9b0c5ed5c8c1fe90cd486d13d0679f0c to your computer and use it in GitHub Desktop.
Save PThorpe92/9b0c5ed5c8c1fe90cd486d13d0679f0c to your computer and use it in GitHub Desktop.
Dockerfile for static musl builds for Rust programs to run on scratch 7mb container
FROM rust:slim as builder
RUN apt-get update && apt-get install -y libpq-dev libssl-dev pkg-config musl-tools perl make && rm -rf /var/lib/apt/lists/*
RUN export OPENSSL_STATIC=1
RUN export OPENSSL_NO_VENDOR=Y
RUN rustup target add x86_64-unknown-linux-musl
WORKDIR /app
COPY . /app
RUN cargo build --release --target x86_64-unknown-linux-musl
RUN strip /app/target/x86_64-unknown-linux-musl/release/bt_postgres_test
#FROM gcr.io/distroless/cc-debian12:latest
FROM scratch
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/bt_postgres_test /s
WORKDIR /
CMD ["/s"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment