Fly.io is a global application distribution platform. We run your code in Firecracker microVMs around the world.
In this work-through we’re going to deploy an application to Fly. In this example, the application will come from a docker image, but first, we want to install all the tools you need to work with Fly. Which is one tool, flyctl.
Flyctl is a command-line utility that lets you work with Fly, from creating your account to deploying your applications. It runs on your local device so you’ll want to install the version that’s appropriate for your operating system:
If you have the Homebrew package manager installed, flyctl can be installed by running:
brew install superfly/tap/flyctl
If not, you can run the install script:
curl -L https://fly.io/install.sh | sh
Run the install script:
curl -L https://fly.io/install.sh | sh
Run the Powershell install script:
iwr https://fly.io/install.ps1 -useb | iex
Signing up for Fly
If it’s your first time using Fly, you’ll need to sign up for an account. To do so, run:
flyctl auth signup
This will take you to the sign-up page where you can either:
Sign-up with email: Enter your name, email and password.
Sign-up with github: If you have a Github account, you can use that to sign up. Look out for the confirmatory email we’ll send you which will give you a link to set a password; you’ll need a password set so we can actively verify that it is you for some Fly operations.
You will also be prompted for credit card payment information, required for charges outside the free tier on Fly. See Pricing - https://fly.io/docs/about/pricing for more details on what is included in the free tier… If you do not enter a details here, you will be unable to create a new application on Fly until you add a credit card to your account.
Whichever route you take you will be signed up, signed in, and returned to your command line, ready to use Fly.
Already got a Fly Account? Sign in!
If you already have a Fly account, all you need to do is sign in with Flyctl. Simply run:
flyctl auth login
Your browser will open up with the Fly sign-in screen, enter your user name and password to sign in. If you signed up with Github, use the Sign in with Github button to sign in.
Whichever route you take you will be returned to your command line, ready to use Fly.
Creating an App on Fly
Fly allows you to deploy any kind of app as long as it is packaged in a Docker image. That also means you can just deploy a docker image and as it happens we have one ready to go in flyio/hellofly:latest.
Each Fly application needs a fly.toml file to tell the system how we’d like to deploy it. That file can be automatically generated with the flyctl launch command.
flyctl launch --image flyio/hellofly:latest
Organizations: Organizations are a way of sharing applications and resources between Fly users. Every fly account has a personal organization, called personal, which is only visible to your account. Let’s select that for this guide.
? Select region: ord (Chicago, Illinois (US))
Next, you’ll be prompted to select a region to deploy in. The closest region to you is selected by default. You can use this or change to another region.
You will also be prompted for credit card payment information, required for charges outside the free tier on Fly. See Pricing for more details on what is included in the free tier. If you do not enter a details here, you will be unable to create a new application on Fly until you add a credit card to your account.
At this point, flyctl creates an app for you and writes your configuration to a fly.toml file. The fly.toml file now contains a default configuration for deploying your app.
The flyctl command will always refer to this file in the current directory if it exists, specifically for the app name value at the start. That name will be used to identify the application on the Fly platform. You can also see how the app will be built and that internal port setting. The rest of the file contains settings to be applied to the application when it deploys.
We’ll have more details about these properties as we progress, but for now, it’s enough to say that they mostly configure which ports the application will be visible on.
Deploying an App to Fly
We are now ready to deploy our containerized app to the Fly platform. At the command line, just run:
This will lookup our fly.toml file, and get the app name hellofly from there. Then flyctl will start the process of deploying our application to the Fly platform. Flyctl will return you to the command line when it’s done.
Viewing an App on Fly
Now the application has been deployed, let’s find out more about its deployment. The command flyctl status will give you all the essential details.
As you can see, the application has been deployed with a DNS hostname of hellofly.fly.dev. Your deployment’s name will, of course be different. We can also see that one instace of the app is now running in the fra (Frankfurt) region. Next, we connect to it.
Connecting to an App on Fly
The quickest way to connect to your deployed app is with the flyctl open command. This will open a browser on the http version of the site. That will automatically be upgraded to a https secured connection (when using the fly.dev domain) to connect to it securely. Add /name to flyctl open and it’ll be appended to the apps path and you’ll get an extra greeting from the hellofly application.
flyctl open /fred
You have successfully deployed and connected to your first Fly application.