Run an Astro App

Getting an application running on Fly.io is essentially working out how to package it as a deployable image. Once packaged it can be deployed to the Fly.io platform.

In this guide we’ll learn how to deploy an Astro application on Fly.io.

You can deploy your Astro app on Fly.io with minimal effort, our CLI will do the heavy lifting. You can use your existing Astro app or you can create one from scratch.

Astro applications can be served as either static pages or with server-side rendering (SSR). On this page you’ll find guides to deploying both varieties.

Deploy a static Astro site


First, install flyctl, the Fly.io CLI, and sign up to Fly.io if you haven’t already.

Next, if you don’t have an existing Astro application, you can create one with the following command:

npm create astro@latest

With the project setup out of the way, you’re ready to start deploying! If you don’t have a Dockerfile yet, fly launch will generate one for you, as well as prepare a fly.toml file.

cd my-astro-app
fly launch
Scanning source code
Detected an Astro app
Creating app in [redacted]/my-astro-app
We're about to launch your NodeJS app on Fly.io. Here's what you're getting:

Organization: Your Name                (fly launch defaults to the personal org)
Name:         my-astro-app             (derived from your directory name)
Region:       Seattle, Washington (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? (y/N) No
Created app 'my-astro-app' in organization 'personal'
Admin URL: https://fly.io/apps/my-astro-app
Hostname: my-astro-app.fly.dev
installing: npm install @flydotio/dockerfile@latest --save-dev

...

found 0 vulnerabilities
     create  Dockerfile
Wrote config file fly.toml
Validating [redacted]/my-astro-app/fly.toml
Platform: machines
✓ Configuration is valid

==> Building image
...
--> Building image done
==> Pushing image to fly
...
--> Pushing image done
...

Watch your deployment at https://fly.io/apps/my-astro-app/monitoring

Provisioning ips for my-astro-app
  Dedicated ipv6: 2a09:6739:1::30:xxxx:0
  Shared ipv4: 66.241.124.xxx
  Add a dedicated ipv4 with: fly ips allocate-v4

This deployment will:
 * create 2 "app" machines

No machines in group app, launching a new machine
Creating a second machine to increase service availability
Finished launching new machines
-------
NOTE: The machines for [app] have services with 'auto_stop_machines = true' that will be stopped when idling

-------
Checking DNS configuration for my-astro-app.fly.dev

Visit your newly deployed app at https://my-astro-app.fly.dev/

That’s it! Run fly apps open to see your deployed app in action.

Try a few other commands:

Deploy an Astro site with SSR


Astro supports server-side rendering (SSR) through the use of adapters. There are a handful of adapters that are officially maintained by the Astro team. When using the @astrojs/node adapter, Fly.io will automatically detect this during fly launch and if no existing Dockerfile is found, it will generate a new one with the appropriate start command and environment variables.

You can add the necessary Node adapter like so:

npx astro add node

This will install @astrojs/node and make the appropriate changes to your astro.config.* file in one step.

Generating your Astro Dockerfile

As discussed earlier, running fly launch will generate a Dockerfile for you if one does not already exist. Separately, you can also generate your Dockerfile using Dockerfile generator. Once installed, it can be run using npx dockerfile for Node applications or bunx dockerfile for Bun applications. You’ll see it referenced throughout this article for various use cases.