DEV Community

Alex Spinov
Alex Spinov

Posted on

Fly.io Has a Free API — Deploy Docker Apps Globally With 3 VMs Free

Global Deployment in One Command

Fly.io runs your Docker containers close to users worldwide. Free tier: 3 shared VMs, 160GB bandwidth, 3GB persistent storage.

Setup

curl -L https://fly.io/install.sh | sh
fly auth login
fly launch  # Auto-detects your app type
fly deploy
Enter fullscreen mode Exit fullscreen mode

REST API

import requests

TOKEN = "your_fly_api_token"  # fly tokens create
HEADERS = {"Authorization": f"Bearer {TOKEN}"}

def list_apps():
    r = requests.get("https://api.machines.dev/v1/apps",
                     headers=HEADERS)
    return [{"name": a["name"], "status": a["status"]} for a in r.json()]

def scale_app(app_name, count):
    r = requests.post(f"https://api.machines.dev/v1/apps/{app_name}/machines",
                      headers=HEADERS, json={"config": {"image": "your-image"}})
    return r.json()
Enter fullscreen mode Exit fullscreen mode

GraphQL API (Machines)

def fly_graphql(query):
    r = requests.post("https://api.fly.io/graphql",
                      headers={**HEADERS, "Content-Type": "application/json"},
                      json={"query": query})
    return r.json()

# Get app details
result = fly_graphql("""{ apps { nodes { name status hostname } } }""")
for app in result["data"]["apps"]["nodes"]:
    print(f"{app[name]}: {app[status]} ({app[hostname]})")
Enter fullscreen mode Exit fullscreen mode

Fly.io vs Alternatives

Feature Fly.io Render Railway Heroku
Free VMs 3 1 $5 credit None
Global edge 35 regions 4 regions 1 region 2 regions
Docker Full Full Full Limited
Persistent storage 3GB free 1GB 1GB None free
Auto-scaling Yes Manual Manual Manual

More | GitHub


More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs

Top comments (0)