Serve — Docker
Package a Rank HTTP app into a container image using rank serve.
Source
examples/serve-docker/main.rank
use std::HTTP
HealthRoute = HTTP::Route {
method: `GET`,
path: `/health`
}
Routes = HealthRoute
pub config = {
defaultResponseFormat: `json`
}
pub main = || -> HTTP::Response {
return {
status: 200,
body: {
ok: true,
service: `serve-docker-example`
}
}
}
examples/serve-docker/rank.toml
manifestVersion = 1
[package]
name = "serve-docker-example"
version = "0.1.0"
source = "."
examples/serve-docker/Dockerfile
FROM node:22-slim
WORKDIR /app
RUN npm install -g @rank-lang/cli
COPY rank.toml main.rank ./
RUN rank sync .
EXPOSE 3000
CMD ["rank", "serve", ".", "--host", "0.0.0.0", "--port", "3000"]
Build and run
docker build -t rank-serve-example .
docker run --rm -p 3000:3000 rank-serve-example
curl http://127.0.0.1:3000/health
{
"ok": true,
"service": "serve-docker-example"
}
For local parity without Docker:
rank serve . --host 127.0.0.1 --port 3000
Key concepts
rank sync .— runs during the Docker build to cache all registry dependencies. The container starts without making outbound package requests.--host 0.0.0.0— binds to all interfaces so traffic forwarded by Docker reaches the server. In local development use127.0.0.1(the default).pub config— setsdefaultResponseFormat: \json`so all route responses are serialized as JSON without having to specifyformat` on each one./.well-known/rank/ready— built-in readiness endpoint managed by the server runtime, not part of the application route table. Use it for Docker health checks or load-balancer probes.