xiaohongshu
xiaohongshu
fly-deployment
Use when deploying to Fly.io - covers single volume limitation, monorepo deployment, Dockerfile patterns for Next.js/Python, and common troubleshooting
Full skill instructions
Comprehensive guide for deploying applications to Fly.io, covering configuration, Dockerfiles, volumes, and common pitfalls. Based on official documentation and real deployment experience.
A Machine can only mount ONE volume. This is the most common gotcha.
# WRONG - Will fail with "only 1 volume supported"
[[mounts]]
source = "data"
destination = "/data"
[[mounts]]
source = "repos"
destination = "/repos"
# CORRECT - Single volume with subdirectories
[[mounts]]
source = "app_data"
destination = "/data"
# Then use /data/repos, /data/db, etc. in your app
Other volume constraints:
When using fly deploy --config path/to/fly.toml:
For monorepos, place fly.toml files in the project root with dockerfile paths like apps/api/Dockerfile.
app = "my-app"
primary_region = "dfw"
[build]
dockerfile = "Dockerfile"
[env]
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
[[vm]]
memory = "512mb"
cpu_kind = "shared"
cpus = 1
app = "my-api"
primary_region = "dfw"
[build]
dockerfile = "apps/api/Dockerfile"
[env]
DB_PATH = "/data/app.db"
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = false # Keep running for API
auto_start_machines = true
min_machines_running = 1
[[mounts]]
source = "app_data"
destination = "/data"
[[vm]]
memory = "1gb"
cpu_kind = "shared"
cpus = 1
[build]
dockerfile = "apps/web/Dockerfile"
[build.args]
NEXT_PUBLIC_API_URL = "https://my-api.fly.dev"
[env]
PORT = "3000"
NODE_ENV = "production"
NEXT_PUBLIC_API_URL = "https://my-api.fly.dev"
FROM node:20-alpine AS base
# Dependencies
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
# Builder
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
RUN npm run build
# Runner
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
Requirements:
next.config.js must have output: 'standalone'sharp if using Next.js Image optimizationFROM python:3.11-slim
RUN apt-get update && apt-get install -y \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# IMPORTANT: Use exec form and --proxy-headers for Fly's TLS proxy
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--proxy-headers"]
Pull binaries from official images instead of version-pinning downloads:
# Pull tools from official images (always latest)
FROM ghcr.io/gitleaks/gitleaks:latest AS gitleaks
FROM aquasec/trivy:latest AS trivy
FROM python:3.11-slim
# Copy binaries
COPY --from=gitleaks /usr/bin/gitleaks /usr/local/bin/gitleaks
COPY --from=trivy /usr/local/bin/trivy /usr/local/bin/trivy
# ... rest of Dockerfile
project-root/
├── fly.api.toml # API config (in root)
├── fly.web.toml # Web config (in root)
├── apps/
│ ├── api/
│ │ ├── Dockerfile # Paths relative to root
│ │ └── ...
│ └── web/
│ ├── Dockerfile # Paths relative to root
│ └── ...
# From project root
fly deploy --config fly.api.toml
fly deploy --config fly.web.toml
Since Dockerfiles are built with root as context:
# In apps/api/Dockerfile
COPY apps/api/requirements.txt .
COPY apps/api/*.py /app/
# In apps/web/Dockerfile
COPY apps/web/package*.json ./
COPY apps/web/ .
# Create apps
fly apps create my-app --org my-org
# Create volume (pick region with good capacity)
fly volumes create app_data --size 10 --app my-app --region dfw
# Check region capacity first
fly platform regions
# Set secrets
fly secrets set \
API_KEY="xxx" \
DB_URL="yyy" \
--app my-app
# Deploy
fly deploy --config fly.api.toml
# View logs
fly logs --app my-app
# SSH into machine
fly ssh console --app my-app
# Check status
fly status --app my-app
# List volumes
fly volumes list --app my-app
Check capacity before choosing:
fly platform regions
Pick regions with positive capacity scores. Negative scores mean constrained resources.
Good US options (typically):
dfw - Dallaslax - Los Angelesord - ChicagoYou have multiple [[mounts]] sections. Consolidate to one volume with subdirectories.
Example: /apps/api/apps/api/Dockerfile
Cause: fly.toml is in a subdirectory with relative dockerfile path.
Fix: Place fly.toml in project root with full path: dockerfile = "apps/api/Dockerfile"
Symptom: COPY apps/web/ . fails with "not found"
Fix: Deploy from project root: fly deploy --config fly.web.toml
Test locally first:
cd apps/web && npx tsc --noEmit
Check that app binds to 0.0.0.0, not localhost or 127.0.0.1.
For apps behind Fly's TLS proxy, add --proxy-headers to uvicorn or equivalent for your framework.
Symptom: Build fails with errors like:
Error: useAuth must be used within an AuthProvider
Error occurred prerendering page "/dashboard"
Cause: Next.js tries to statically pre-render pages at build time. If pages use React Context hooks (like useAuth, useTheme, etc.) but the Provider isn't wrapping the component tree during SSG, the build fails.
Fix: Ensure your context Provider wraps the entire app in layout.tsx:
// src/components/Providers.tsx
'use client'
import { ReactNode } from 'react'
import { AuthProvider } from '../hooks/useAuth'
export default function Providers({ children }: { children: ReactNode }) {
return <AuthProvider>{children}</AuthProvider>
}
// src/app/layout.tsx
import Providers from '../components/Providers'
import AppLayout from '../components/AppLayout'
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<Providers>
<AppLayout>{children}</AppLayout>
</Providers>
</body>
</html>
)
}
Key points:
Providers component must have 'use client' directiveSymptom: Build fails with:
COPY --from=builder /app/public ./public
failed to calculate checksum: "/app/public": not found
Cause: The standard Next.js Dockerfile copies the public directory, but your project doesn't have one.
Fix: Create an empty public directory:
mkdir -p apps/web/public
touch apps/web/public/.gitkeep
Note: The public directory is where Next.js serves static assets (favicon, images, robots.txt, etc.). Even if empty, the directory must exist for the Dockerfile COPY to succeed.
Free tier includes:
To minimize costs:
auto_stop_machines = true for non-critical appsmin_machines_running = 0 when possible256mb memory, increase if neededxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience