Fly.io runs your Docker containers as lightweight Firecracker micro-VMs at the network edge. It's more powerful than Render or Railway for teams who want fine-grained control over machine placement, scaling, and networking — but the learning curve is steeper. This guide gets you from a Dockerfile to a live deployment.

Install flyctl

# macOS
brew install flyctl
 
# Linux
curl -L https://fly.io/install.sh | sh
 
# Windows (PowerShell)
iwr https://fly.io/install.ps1 -useb | iex
 
# Authenticate
fly auth login

Step 1: Write a Dockerfile

Fly.io deploys any Docker image. If your project doesn't have a Dockerfile, fly launch will generate one. For AI applications, here's a solid starting point for a Python FastAPI app:

FROM python:3.11-slim
 
WORKDIR /app
 
# Install dependencies first (cached layer)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
 
# Copy application code
COPY . .
 
# Fly injects the PORT environment variable
ENV PORT=8080
EXPOSE 8080
 
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

Step 2: Launch the App

# Run from your project directory
fly launch
 
# fly launch asks:
# - App name (or generate one)
# - Organisation
# - Region (pick the closest to your users)
# - Whether to add a Postgres database
# - Whether to deploy now
 
# This creates fly.toml in your project directory

fly launch generates a fly.toml configuration file. Review it before deploying — especially the [[services]] section which defines the port mapping and health checks.

Step 3: Review fly.toml

app = 'your-app-name'
primary_region = 'lhr'  # London — change to your region
 
[build]
 
[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true   # stops idle machines to save cost
  auto_start_machines = true  # restarts on incoming request
  min_machines_running = 0    # set to 1 to avoid cold starts
 
[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1
auto_stop_machines = true with min_machines_running = 0 means your app will have cold starts (5–10 seconds). For production AI apps, set min_machines_running = 1 to keep at least one machine always running.

Step 4: Set Secrets

# Set secrets (encrypted, not visible after setting)
fly secrets set OPENAI_API_KEY=sk-...
fly secrets set DATABASE_URL=postgresql://...
 
# List current secrets (values are redacted)
fly secrets list

Step 5: Deploy

fly deploy
 
# Fly builds your Docker image, pushes it to the registry,
# starts new VMs, runs health checks, then cuts over traffic
 
# Watch the deployment logs
fly logs
 
# Open your app in the browser
fly open

Step 6: Custom Domain

# Add a custom domain
fly certs add yourdomain.com
 
# Fly outputs the DNS records to add (A record + AAAA for IPv6)
fly certs show yourdomain.com
 
# Check certificate status
fly certs check yourdomain.com

Useful Day-to-Day Commands

fly status          # machine status and health
fly logs            # stream live logs
fly ssh console     # SSH into a running machine
fly scale count 2   # run 2 machines
fly deploy          # redeploy after code changes
Metadata Value
Title Your First App on Fly.io: Dockerfile to Production in 20 Minutes
Tool Fly.io
Primary SEO keyword deploy app fly.io
Secondary keywords fly.io tutorial, flyctl deploy, fly.io docker, fly.io fastapi
Estimated read time 8 minutes
Research date 2026-04-14