Deploy previews for Rust apps
Push a branch, get a live preview URL. PreviewDrop compiles your Rust server, runs the binary as a long-lived process, and posts the link to the pull request, usually within a couple of minutes.
What the build needs to do
You don't write this. PreviewDrop detects Rustfrom your repo and builds the container for you — a Dockerfile in your repo is not used. The reference below shows the install, build and start steps a working Rust image needs. If detection gets one wrong, set the matching Install, Build or Start command in Project Settings. Your app must listen on $PORT.
Reference (not read by PreviewDrop)FROM rust:1.82 AS build WORKDIR /app COPY Cargo.toml Cargo.lock ./ # Pre-build dependencies in their own layer for fast rebuilds RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release && rm -rf src COPY . . RUN cargo build --release FROM debian:bookworm-slim RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* # Replace "yourapp" with your crate's binary name COPY --from=build /app/target/release/yourapp /usr/local/bin/app EXPOSE 8080 ENV PORT=8080 CMD ["app"]
Environment variables
Set these in the Variables tab of your PreviewDrop project. They're encrypted at rest and injected into every preview container at start.
| Variable | Example value | Note |
|---|---|---|
| PORT | 8080 | PreviewDrop injects this. Read it in main() and bind your listener to it. |
| DATABASE_URL | postgres://user:pass@host:5432/db | For sqlx / SeaORM / Diesel. Omit for stateless previews. |
| RUST_LOG | info | Controls tracing / env_logger verbosity inside the preview container. |
Common gotchas
Bind to 0.0.0.0 and read PORT
TcpListener::bind(("0.0.0.0", port)).await where port comes from std::env::var("PORT"). Binding to 127.0.0.1 makes the container unreachable and the preview will 502.Make sure the right binary starts
target/release/yourapp. That name is your crate’s [[bin]] name (or the package.name in Cargo.toml). If your workspace has more than one binary and the wrong one starts, set the Start command in Project Settings to the one you want.Outbound HTTPS needs root certificates
ca-certificates for that reason.Keep release builds fast
main.rs trick compiles your dependency tree in its own layer, so a change to application code doesn’t recompile every crate, which keeps builds fast. For larger projects, cargo-chef does this more robustly.Why not Vercel or Netlify?
Preview your Rust app in 5 minutes
Connect a repo, push a branch, get a URL. No credit card, no trial clock.
Start free