1# =============================================================================2# Rust Production Dockerfile3# =============================================================================4# Customize the following before use:5# - APP_NAME: Replace "app" with your binary name from Cargo.toml6# - PORT: Change EXPOSE port if not 80807#8# Notes:9# - The dependency-caching trick creates a dummy main.rs, builds10# dependencies, then replaces it with real source — this avoids11# rebuilding all deps on every source change12# - The final image uses distroless/cc which includes libgcc/libstdc++13# needed by the default Rust allocator; if you use musl14# (--target x86_64-unknown-linux-musl) switch to distroless/static
43# 2. Copy real source and build the actual binary.
44COPY src ./src
45
46RUN cargo build --release
47
48# Verify binary exists with expected name
49RUN test -f /app/target/release/app || (echo "ERROR: Binary 'app' not found at /app/target/release/app"; echo "The binary name in Cargo.toml must be 'app'."; echo "Update [[bin]] section in Cargo.toml to set name = \"app\""; echo "Also verify the COPY step above uses the correct binary name."; exit 1)