How to Deploy an Application
A Salvo project compiles into an executable file. To deploy, simply upload this executable along with its dependent static resources to your server.
For Rust-based projects, there is also a very simple deployment platform: shuttle.rs. Shuttle provides support for Salvo projects. For details, please refer to the official documentation.
Docker Deployment
You can also deploy Salvo applications using Docker. Below is a basic Dockerfile
example that you can adjust according to your project's requirements:
# Build stage
FROM rust:slim AS build
WORKDIR /app
# Copy dependency files first to build dependencies (utilizing cache layers)
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && \
echo 'fn main() { println!("Placeholder"); }' > src/main.rs && \
cargo build --release
# Copy actual source code and build the application
COPY src ./src/
RUN touch src/main.rs && \
cargo build --release
# Runtime stage using a minimal base image
FROM debian:bookworm-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create a non-root user to run the application
RUN useradd -ms /bin/bash appuser
USER appuser
WORKDIR /app
# Copy the binary from the build stage
COPY --from=build /app/target/release/your_app_name ./app
# Set the container startup command
CMD ["./app"]
Usage Instructions
- Save the above
Dockerfile
in your project's root directory
- Adjust
your_app_name
to match your actual binary filename
- If your application requires static files (such as templates, CSS, JS, etc.), add the corresponding
COPY
commands
- If your application needs environment variable configuration, use the
ENV
directive
- Build the Docker image:
docker build -t your-app-name .
- Run the container:
docker run -p 5800:5800 your-app-name
Please adjust the port number and other configurations according to your application's actual requirements.