This is an example app demonstrating how to deploy a Rust program on Fly.io
Warp-based "hello world" app, as simple as it can get.
Noticed this line?
warp::serve(routes)
// ipv6 + ipv6 any addr
.run(([0, 0, 0, 0, 0, 0, 0, 0], 8080))
.await;
This listens to all addresses on both IPv4 and IPv6, on port 8080. It's important to do this because your app would otherwise need to know about the 172.19.0.0/16
IP it should bind to specifically. Binding to IPv6 is not required, but is likely a good idea going forward.
A fairly standard fly.toml
configuration, except for the cmd
override:
[experimental]
cmd = "./hello" # should be the name of the binary you want to run
The most efficient way to create a Docker image for a Rust app is a simple Dockerfile.
Our Dockerfile
is heavily commented, but here's a short rundown:
- Copy
Cargo.{toml,lock}
and build dependencies - Copy whole project and
cargo install
it
You definitely want to ignore /target
since this can get pretty hefty, adding to the build context's size, and slow down builds significantly.
fly launch