Deploy via Dockerfile
You already have a project wrapped up in a docker container? Great! Just deploy that!
The fly launch
command detects your Dockerfile, builds it, and then deploys your app. Need some extra config? No sweat, we’ve got you covered.
If you want to configure more than the basic settings, things like secrets or environment variables for example, then run fly launch --no-deploy
so that you can edit the fly.toml
file before the first deployment.
fly launch
Scanning source code
Detected a Dockerfile app
Creating app in /Users/name/test/my-app-name
We're about to launch your app on Fly.io. Here's what you're getting:
Organization: MyOrg (fly launch defaults to the personal org)
Name: my-app-name (derived from your directory name)
Region: Secaucus, NJ (US) (this is the fastest region for you)
App Machines: shared-cpu-1x, 1GB RAM (most apps need about 1GB of RAM)
Postgres: <none> (not requested)
Redis: <none> (not requested)
? Do you want to tweak these settings before proceeding? Yes
Type n
if you’re happy with the defaults listed, otherwise type y
to open the Fly Launch web page and edit your settings, including:
Name: Keep the default app name or enter your own.
Region: Keep the fastest region (the value of
primary_region
in thefly.toml
file) as chosen by Fly Launch, or select a different region to deploy to.Services: The port for services (the value of
internal_port
in thefly.toml
file) depends on theEXPOSE
instruction in your Dockerfile. The default port when thefly launch
command doesn’t find ports set in a Dockerfile is8080
.You can also set a default Machine size and memory, and add and configure Postgres or Redis.
After you click Confirm Settings, Fly Launch creates your app, generates a fly.toml
file for your project with the settings, and then deploys the app.
More config!
Most Dockerfiles expect some configuration settings through ENV
. The generated fly.toml
file has a place for you to add your custom ENV
settings. It’s the [env]
block.
[env]
MY_SPECIAL_ENV = "some_value"
MAX_PLAYER_COUNT = "15"
Add the values your Dockerfile requires.
Sometimes you have secrets that shouldn’t be checked in to git
or shared publicly. For those settings, you can set them using fly secrets
.
flyctl secrets set MY_SECRET=romance
Secrets are staged for the first deployment
You can list the secrets you’ve already set using fly secrets list
fly secrets list
NAME DIGEST DATE
MY_SECRET b9e37b7b239ee4aefc75352fe3fa6dc6 1m20s ago
The values aren’t displayed, since they’re secret!
Deploy your app
If you didn’t deploy the new app, or you’ve made changes and want to redeploy, then you can do that now.
fly deploy
==> Verifying app config
Validating /Users/name/test/my-app-name/fly.toml
Platform: machines
โ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-long-glitter-7257 ready
==> Building image with Docker
...
--> Pushing image done
image: registry.fly.io/my-app-name:deployment-01HGEQ1Z1DPMJ4NMPNHTA09T6T
image size: 141 MB
Watch your deployment at https://fly.io/apps/my-app-name/monitoring
-------
Updating existing machines in 'my-app-name' with rolling strategy
-------
โ [1/2] Machine 918543b477de83 [app] update succeeded
โ [2/2] Machine e28697ce6d3986 [app] update succeeded
-------
Visit your newly deployed app at https://my-app-name.fly.dev/
By default, fly deploy
builds the image using a remote builder. If you have Docker running locally and want to build locally, then run fly deploy --local-only
. After the image is built, the app gets deployed.
Open your app
Run fly apps open
, or just go to the URL specified in the output, to open your deployed app in a browser.
You’re off and running!
Taking it further
Lots of apps have some state that they want to keep. Here are a couple resources to check out for ways to do that.
- Persistent Volumes: You can create persistent volumes for reading and writing data that changes but isn’t blown away when you deploy again.
- Postgres Database: Deploy a Fly Postgres Database. It automatically creates a
DATABASE_URL
ENV when you attach it to your app.