Detection
migetpacks detects Rust when any of these files are present in your project root:Cargo.tomlCargo.lock
Version Detection
Rust version is resolved in this order:Build Process
migetpacks generates a multi-stage Dockerfile with an optimized dependency caching strategy:Dependency Caching Strategy
Rust’s dependency caching uses a “dummy source” technique:- Copy
Cargo.tomlandCargo.lock - Create a minimal
fn main() {}source file - Run
cargo build --releaseto compile all dependencies - Remove the dummy source
- Copy the real source code
- Touch
src/main.rsto invalidate only the application crate - Rebuild — only the application code recompiles
Binary Detection
The binary name is automatically detected fromCargo.toml:
[[bin]]sectionnamefield[package]sectionnamefield- Falls back to
app
Workspace Projects
For workspace projects (when[workspace] is present in Cargo.toml), all workspace member Cargo.toml files are copied for proper dependency resolution.
Static Assets
If your project containsstatic/, public/, assets/, templates/, dist/, or build/ directories, they are automatically copied alongside the binary to the runtime image.
Run Command
The default run command is determined in this order:Procfile commands referencing
./target/release/binary are automatically translated to ./app since the binary is copied to the application root during build.Runtime Environment
The following environment variables are set in the runtime container:Caching
Docker Layer Caching
The dummy-source technique ensures thatcargo build --release for dependencies is cached when only source code changes. A full dependency rebuild only happens when Cargo.toml or Cargo.lock is modified.
BuildKit Cache Mounts
WhenBUILD_CACHE_DIR is configured, BuildKit cache mounts are used:
Registry Cache
UseCACHE_IMAGE to push/pull BuildKit inline cache layers to a registry for cross-build caching.
DHI Support
Rust is fully supported with Docker Hardened Images.
The
-dev variant includes a shell and build tools (cargo, rustc). The runtime image is distroless with no shell, providing a minimal attack surface.
Since Rust produces static binaries, the distroless runtime works without any special handling.