Railway

Deploy Rocket | Rust JSON API in an 18 MB Container

Rocket 0.5 on current Rust, committed lockfile, 18 MB runtime image

Deploy Rocket | Rust JSON API in an 18 MB Container

Deploy and Host a Rocket API on Railway

A Rocket 0.5 JSON API on current Rust, in an 18 MB container.

About Hosting Rocket

The Rocket template on Railway builds from a repository last touched in May 2023, and none of its deployments come up. The reason is one line in its Cargo.toml:

rocket = "0.5.0-rc.1"

That is a release candidate published in 2022. Rocket 0.5.0 shipped as a final release in November 2023 and is now at 0.5.1, but the pin holds the project on the prerelease, whose dependency tree no longer resolves against current crates.

This template pins 0.5.1 and commits Cargo.lock, so a build a year from now produces the same binary as today rather than depending on what crates.io looked like that morning.

Common Use Cases

  • A small JSON API where the cost per request matters
  • A service that has to sit in a tight memory budget - the whole image is 18 MB
  • A Rust component alongside services written in something else

Dependencies for Rocket Hosting

  • Nothing. One service, no database. Add sqlx or diesel and a Postgres service when you need persistence.

Deployment Dependencies

Implementation Details

MethodPathDoes
GET/Lists the endpoints
GET/health{"status":"ok"}
GET/greet?name=worldGreets, 400 with a readable body when name is missing

Three details worth keeping if you rewrite this:

  • Rocket.toml binds 0.0.0.0. Rocket listens on 127.0.0.1 by default, which inside a container means nothing outside it can connect - a service that looks healthy in the logs and answers nobody.
  • ROCKET_PORT is set from PORT in the entrypoint. Rocket reads its own environment variable; the platform provides a different one.
  • Dependencies build before the sources are copied. The build stage compiles a placeholder main.rs first, so editing real code reuses that layer instead of rebuilding all 162 crates. Rust rewards this more than most languages.

The release profile turns on link-time optimisation and strips symbols. That costs build time once and gives a runtime image of 18 MB, which is most of why a redeploy is quick.

Why Deploy Rocket on Railway?

Push Rust, get a running service on a domain with TLS and a health check. The container is small enough that deploys are fast and the memory bill stays boring.


Template Content

More templates in this category

View Template
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
1
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5
View Template
Flask WebSocket Chat
Single file, realtime multi-user websocket chat using flask-socketio

Clement Ochieng
3