FROM rust as planner
WORKDIR /app
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM rust as cacher
WORKDIR /app
RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
FROM rust AS builder
ENV USER=webuser
ENV UID=6969
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
COPY . /app
WORKDIR /app
COPY --from=cacher /app/target target
RUN cargo build --release
FROM gcr.io/distroless/cc-debian11
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /app/target/release/docker-rust /app/docker-rust
WORKDIR /app
CMD ["./docker-rust"]
Created
July 10, 2023 20:06
-
-
Save edr3x/89d4ebdd548bc005a57916e8dcf0b268 to your computer and use it in GitHub Desktop.
dockerfile for containerizing rust
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment