Skip to main content

Containerizing Rust Apps

Below is a sample Dockerfile for containerizing your Rust applications. It uses a tool called cargo chef to speed up compilation times in Rust.

FROM rust:1.86 as base
RUN cargo install cargo-chef --version ^0.1
FROM base AS planner
WORKDIR /app
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM base as builder
WORKDIR /app
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build