Docker
A multi-stage image for an Ulo binary, the signals a container delivers, and compose for local dependencies.
Dockerfile
A multi-stage build compiles in a builder image and ships only the binary and the files it reads at run time. This image is for a project made by ulo new, named my-app, which reads config/app.toml from its working directory.
FROM rust:1.88-bookworm AS builder
WORKDIR /app
# Build the dependencies first, so a source change does not rebuild them.
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -rf src target/release/deps/my_app*
COPY src ./src
RUN cargo build --release
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/target/release/my-app ./my-app
COPY config ./config
EXPOSE 8080
ENV APP_SERVER__ADDRESS=0.0.0.0:8080
CMD ["./my-app"]- The builder's Rust version has to meet the highest floor among the crates used: 1.88 for the workspace, more for
ulo-http-salvo(1.92), sqlx and SeaORM (1.94), diesel and async-graphql (1.89). See Installation. Cargo.lockis copied so the image builds the versions the project was tested with. A project whose dependencies are git tags needs no extra setup in the builder: cargo fetches them.APP_SERVER__ADDRESSoverridesserver.addressfromconfig/app.toml, which holds127.0.0.1:3000. Inside a container the server has to bind0.0.0.0.ulo-rpc-kafkabuilds librdkafka and needs a C toolchain in the builder; therustimage has one.
docker build -t my-app .
docker run -p 8080:8080 my-appSignals
docker stop sends SIGTERM and kills the container after ten seconds (--time changes it). The binary's serve(shutdown_signal()) resolves on SIGTERM, drains in-flight requests for up to drain_timeout (10 seconds unless set), and exits. Set shutdown_timeout below the stop timeout, as in Production.
A container that runs CMD ["./my-app"] makes the binary process 1, which receives the signal directly. A shell-form CMD ./my-app puts a shell at process 1, which may not pass SIGTERM on.
Health check
ulo new projects serve /health/live, /health/ready and /health/started. A compose or Kubernetes probe reads them:
healthcheck:
test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8080/health/ready"]
interval: 10s
timeout: 3s
start_period: 25sdebian:bookworm-slim has no curl. Install it in the runtime stage, or probe from the orchestrator. Readiness answers 503 until the application's checks pass, and turns false at the start of a shutdown. A database module retries its connection before connect fails (see Database), and start_period should cover that.
docker-compose
For local development with a database:
services:
api:
build: .
ports:
- "8080:8080"
environment:
APP_DATABASE__URL: postgres://postgres:password@db:5432/app
RUST_LOG: debug
depends_on:
db:
condition: service_healthy
restart: unless-stopped
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: app
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5APP_DATABASE__URL overrides database.url, the key ulo new --db sqlx-postgres writes. The depends_on condition starts the application once Postgres answers. A store module checks its server at connect, and an application whose database is not up fails to start. restart: unless-stopped covers the remaining races.
Static binary with musl
rustup target add x86_64-unknown-linux-musl
# the builder needs a musl C toolchain (musl-tools on Debian)
cargo build --release --target x86_64-unknown-linux-muslA musl binary has no libc dependency, which makes scratch or a distroless base image viable:
FROM scratch
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/my-app /my-app
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY config /config
WORKDIR /
EXPOSE 8080
ENV APP_SERVER__ADDRESS=0.0.0.0:8080
CMD ["/my-app"]