
Do I need to control Machines directly?
We give you low-level control over Fly Machines for when you need to be picky about how, where, and when to start VMs on Fly.io. For most applications, most of the time, you donāt need to be picky! You scale things up to more cores or more memory, and out to more regions and more Machine counts. Fly Launch does all that for you with simple syntax and configuration.Concepts
You can create and destroy Machines directly, and you have control over every Machineās lifecycle, resources, and region placement.Machines
A Machine is the configuration and state for a single VM running on Fly.io. Every Machine will belong to a Fly App; Apps can have more than one Machine. You can start a Machine right now, without configuring anything:run a Machine with --shell, weāll make a small one, and weāll tear it down when youāre done poking around.
Machine state
The big Fly Machine trick is: starting up super fast; like, āin response to an HTTP request from a userā fast. Doing things like that is why youād use Fly Machines directly, rather than letting flyctl run your deployment. To get your head around that trick, start by understanding the lifecycle of a Fly Machine:-
You create a Fly Machine with a Create Machine request, or
with
fly machine run. The Machine is increatedstate while we reserve space for your Machine, fetch your container from our global registry, and then build a root file system; this can take some time, maybe low double digit seconds. -
Once the Fly Machine exists, we boot it up for you right away. The Machine is in
startedstate. Itās running. You can talk to it. This happens fast! Everythingās already assembled; weāre just booting. Usually this takes well under a second. The same goes for starting a stopped Machine with a Start Machine request, or withfly machine start. -
Youāre done with the Fly Machine, so you stop it with a Stop Machine request, or
fly machine stop. The VM shuts down. The Machine is instoppedstate. Its components are still assembled on our worker host, ready to start back up; if you want to do that,GOTO 2. -
Youāre tired of the Fly Machine, and want it to go away permanently. Send a Delete Machine request, or use
fly machine destroy. We clear the resources we were holding for the Machine off our server. You can easily create and start a new Machine from the same image, but itāll be slower than stopping and starting an existing Machine.
Scaling Machines
Remember, the ordinary way to scale an application on Fly.io is to use Fly Launch, which offers convenient
commands to scale instances out or up. Here, weāre going to scale Machines directly, in a fiddly way.Whether or not you use
fly launch to boot up a Fly App, every Machine belongs to an āAppā (an āAppā is ultimately just a named
collection of resources, configuration, and routing rules).fly machine clone:
fly machine stop and fly machine start.
Scale a Machine up vertically with fly machine update:
fly machine stop), applies configuration changes, and brings it back up. If youāre
not changing the image, so we donāt have to go fetch it from the global registry, this is fast, for the same reason stop and start
are; weāve already done the heavy lifting.
Static Machine IPs
App-scoped static egress IPs are recommended. The machine-scoped static egress IPs described below are a legacy feature. For most use cases, you should allocate app-scoped static egress IPs instead. Unlike machine-scoped IPs, app-scoped IPs can be shared between multiple machines in a region and are not deleted when machines are recreated.
fly machine egress-ip allocate <machine_id>
Placement
When youcreate, run, or clone a Machine, you can pick a Fly.io region to place it in. Our API will contact the Machines API
server (we call it flaps, but you donāt have to care), which will in turn reach out to all the worker servers we have in the region,
find out which ones have the requisite resources to host the Machine, and try to make a smart choice about which of those servers to
put the Machine in.
You donāt get to pick particular servers (there are ways to cheat and do it anyways, but you shouldnāt want to), just the region.
If you pick a particular region, like ord or yyz, we will only create the Machine in that region.
Read more about Machine placement and regional capacity in this guide.
Recapping Fly Machine features
- Manage with the Machines API or flyctl commands
- Stop automatically when a program exits
- Stop or start quickly, either manually or automatically based on traffic
- Provide ephemeral storage, a blank slate on every startup
- Attach a volume for persistent storage
- Place in any region
Related reading
- Machine states and lifecycle Find out how Machines move through states (created ā started ā stopped etc), what it means, how to detect issues.
- Machine placement and regional capacity Learn more about how region and host capacity affect where your Machines land and what to do if placement fails.
fly machineCLI reference Use this commandāline reference for managing Machines viaflyctl(create, update, stop, clone, etc).- Working with the Machines API Read a practical guide to creating, updating, and managing Machines via API calls.
- Machines API reference Use this low-level reference for the Machines API runtime, generated from the OpenAPI specification.