AgentSkillsCN

railway

Railway.com部署与管理——部署、日志、迁移、故障排除、单体仓库策略、安全及CLI参考。适用于在Railway部署、配置服务、管理环境变量或调试部署问题时使用。

SKILL.md
--- frontmatter
name: railway
description: "Railway.com deployment and management - deployment, logs, migrations, troubleshooting, monorepo strategies, security, and CLI reference. Use when deploying to Railway, configuring services, managing environment variables, or debugging deployment issues."

Railway Deployment & Management

Verification

BEFORE using this skill, verify the project uses Railway:

  1. User explicitly mentions "Railway", OR
  2. Check for Railway artifacts: railway.json, railway.toml, .railway/ directory
  3. When in doubt, ASK: "Is this project deployed to Railway?"

DO NOT use for: Vercel, AWS, Heroku, Fly.io, or unknown platforms.

Quick Reference (CLI 2026-02)

TaskCommand
Deployrailway up --detach
Deploy subdirectoryrailway up --path-as-root ./web
Check statusrailway status
View logsrailway logs
Build logsrailway logs --build
Last N linesrailway logs -n 100
Set variablerailway variable set KEY=VALUE
Set multiplerailway variable set K1=V1 K2=V2
List variablesrailway variable list
List as KVrailway variable list --kv
Delete variablerailway variable delete KEY
Skip redeploy on setrailway variable set K=V --skip-deploys
Connect to DBrailway connect postgres
Run with envrailway run npm start
Open dashboardrailway open
Redeployrailway redeploy --yes
Switch envrailway environment staging
SSH into containerrailway ssh
Service linkrailway service backend
Deployment listrailway deployment list --limit 5
Domainrailway domain

Global Options

These flags work across most commands:

OptionShortPurpose
--service <SERVICE>-sTarget specific service
--environment <ENV>-eTarget specific environment
--project <ID>-pTarget specific project
--jsonScriptable JSON output
--yes-ySkip confirmation prompts

Essential Patterns

Deploy Workflow:

bash
railway status && railway up --detach
railway logs -n 20  # check after deploy

Monorepo Deploy (CRITICAL: use --path-as-root):

bash
railway up --path-as-root ./web --service web
railway up --path-as-root ./backend --service backend

Debug Failed Deployment:

bash
railway logs --build           # Build errors
railway variable list          # Verify env vars
railway run npm run build      # Test locally with Railway env

Database Migration (ALWAYS backup first):

bash
railway run pg_dump -Fc > backup.dump  # 1. BACKUP
railway connect postgres               # 2. Verify state
railway run npm run migrate            # 3. Migrate
railway connect postgres               # 4. Verify

Set Variables:

bash
railway variable set API_KEY=secret123 NODE_ENV=production
railway variable set KEY=VALUE --skip-deploys  # no redeploy
echo "multiline" | railway variable set KEY --stdin

Key Gotchas

  • --path-as-root is required for monorepo subdirectory deploys — without it, subdirectory nests in archive
  • --project requires --environment — both must be specified together
  • Variable changes trigger redeploy by default — use --skip-deploys to prevent
  • railway logs streams live by default; -n N fetches history and exits (NOT --limit)
  • railway variable (singular) is the command — variables, vars, var are aliases
  • TLS between Railway services may fail with UNABLE_TO_GET_ISSUER_CERT_LOCALLY — use NODE_TLS_REJECT_UNAUTHORIZED=0 or private networking
  • CI/CD tokens: RAILWAY_TOKEN (project-scoped) or RAILWAY_API_TOKEN (account-level)

Common Errors

ErrorFix
undefined variable 'npm' in NixpacksDon't add npm to nixPkgs — comes with nodejs
Tracker 'idealTree' already existsnpm cache clean --force && npm install
gyp ERR! build errorAdd nixPkgs = ["nodejs", "python3", "gcc", "gnumake"]
Cannot find module (workspace)Use repo root, not subdirectory, as Root Directory
EACCES: permission deniedUse /tmp for temp files or add a volume
Service crashes on startCheck railway logs, verify env vars, check healthcheck

Additional Resources

Detailed docs in supporting files:

Official: docs.railway.com · CLI Reference