Created
January 9, 2024 09:29
-
-
Save jprochazk/fdfdccc21799e342280a50a764bd13cd to your computer and use it in GitHub Desktop.
minimal rust dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax = docker/dockerfile:experimental | |
# Replace `THE_PROGRAM` with the name of your binary | |
FROM rust:1.75 as builder | |
RUN useradd -m rust | |
ENV HOME /home/rust | |
RUN mkdir -p $HOME/app | |
RUN mkdir -p $HOME/app/target | |
RUN mkdir -p $HOME/binaries | |
RUN chown rust:rust -R $HOME | |
COPY Cargo.lock $HOME/app/Cargo.lock | |
RUN cargo init $HOME/app | |
COPY Cargo.toml $HOME/app/Cargo.toml | |
WORKDIR $HOME/app | |
RUN --mount=type=cache,target=/home/rust/.cargo/git \ | |
--mount=type=cache,target=/home/rust/.cargo/registry \ | |
cargo build --release | |
COPY src $HOME/app/src | |
RUN --mount=type=cache,sharing=private,target=/home/rust/app/target \ | |
cargo install --path . && \ | |
cp $HOME/app/target/release/THE_PROGRAM $HOME/binaries | |
FROM debian:bookworm-slim as runtime | |
RUN apt-get update && \ | |
apt-get install -y ca-certificates && \ | |
update-ca-certificates && \ | |
rm -rf /var/lib/apt/lists/* | |
COPY --from=builder /home/rust/binaries/THE_PROGRAM /usr/local/bin/THE_PROGRAM | |
CMD RUST_BACKTRACE=full THE_PROGRAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment