Back to library

Railway CLI

Skill for Railway CLI — auto-generated from documentation

infrastructure
by skynetv1.0.0
railway-cliinfrastructureauto-generated

0

Total Uses

0

Successes

0%

Success Rate

Compatible Agents

claude-codecodexgemini

Instruction

--- name: Railway CLI description: Use this skill when deploying applications, managing services, or configuring infrastructure on Railway platform. Essential for developers who need to deploy web apps, APIs, databases, and manage Railway projects from the command line. metadata: author: skynet version: 1.0.0 category: infrastructure --- # Railway CLI Railway CLI is a command-line tool for deploying and managing applications on the Railway platform. Use this for rapid deployment of web applications, APIs, databases, and microservices. ## Installation ```bash # Install Railway CLI npm install -g @railway/cli # Or using curl curl -fsSL https://railway.app/install.sh | sh # Verify installation railway --version ``` ## Authentication ```bash # Login to Railway railway login # Login with browser railway login --browserless # Check auth status railway whoami # Logout railway logout ``` ## Project Management ### Creating and Initializing Projects ```bash # Create new project railway new # Initialize in existing directory railway init # Link existing Railway project railway link [project-id] # Clone project from Railway railway clone [project-id] ``` ### Project Information ```bash # Show project status railway status # List all projects railway projects # Show project details railway show # Open project in browser railway open ``` ## Deployment Workflows ### Basic Deployment ```bash # Deploy current directory railway up # Deploy with custom start command railway up --start "npm start" # Deploy specific service railway up --service [service-name] # Deploy with environment railway up --environment production ``` ### Advanced Deployment Options ```bash # Deploy with build command railway deploy --build "npm run build" # Deploy with Dockerfile railway deploy --dockerfile ./Dockerfile # Deploy from GitHub railway deploy --repo owner/repo-name # Deploy specific branch railway deploy --branch main ``` ## Service Management ### Service Operations ```bash # List services railway services # Create new service railway service create [name] # Delete service railway service delete [name] # Connect to service shell railway shell # View service logs railway logs # Follow logs in real-time railway logs --follow # Filter logs by service railway logs --service [service-name] ``` ### Database Services ```bash # Add PostgreSQL railway add postgresql # Add MySQL railway add mysql # Add Redis railway add redis # Add MongoDB railway add mongodb # Connect to database railway connect postgres railway connect mysql railway connect redis ``` ## Environment Management ### Environment Variables ```bash # List all variables railway vars # Set environment variable railway vars set KEY=value # Set multiple variables railway vars set KEY1=value1 KEY2=value2 # Delete variable railway vars delete KEY # Load from .env file railway vars load .env # Export to file railway vars export > .env.backup ``` ### Environment Switching ```bash # List environments railway environments # Switch environment railway environment [env-name] # Create new environment railway environment create [name] # Delete environment railway environment delete [name] ``` ## Domain and Networking ```bash # Generate Railway domain railway domain # Add custom domain railway domain add yourdomain.com # List domains railway domain list # Remove domain railway domain remove yourdomain.com # Show networking info railway info ``` ## Decision Tree: Deployment Strategy ``` Are you deploying for the first time? ├─ YES → railway init → railway up └─ NO → Do you need to update environment variables? ├─ YES → railway vars set KEY=value → railway up └─ NO → Need specific service deployment? ├─ YES → railway up --service [name] └─ NO → railway up ``` ## Common Workflows ### Full Stack App Deployment ```bash # Initialize project railway init # Add database railway add postgresql # Set environment variables railway vars set DATABASE_URL=$DATABASE_URL railway vars set NODE_ENV=production # Deploy application railway up # Check deployment railway status railway logs --follow ``` ### CI/CD Integration ```bash # In CI pipeline export RAILWAY_TOKEN=$RAILWAY_TOKEN railway deploy --service api railway deploy --service frontend # Health check railway status --json | jq '.services[].status' ``` ### Database Migration ```bash # Connect to database railway connect postgres # Run migration command railway run npm run migrate # Seed database railway run npm run seed # Backup database railway run pg_dump $DATABASE_URL > backup.sql ``` ## Troubleshooting ### Common Errors and Solutions **Error: "No project found"** ```bash # Solution: Link to existing project railway link # Or initialize new project railway init ``` **Error: "Build failed"** ```bash # Check logs railway logs --deployment [deployment-id] # Verify build command railway vars set BUILD_COMMAND="npm run build" # Check Node.js version railway vars set NODE_VERSION="18" ``` **Error: "Port binding failed"** ```bash # Ensure your app listens on correct port railway vars set PORT=3000 # In your app code: # const PORT = process.env.PORT || 3000 ``` **Error: "Database connection failed"** ```bash # Check database status railway status # Verify DATABASE_URL railway vars | grep DATABASE # Test connection railway shell ``` ### Performance Issues ```bash # Check resource usage railway metrics # Scale service railway service scale --replicas 2 # Check deployment history railway deployments # Rollback to previous version railway rollback [deployment-id] ``` ### Debugging Commands ```bash # Verbose logging railway --verbose up # Debug mode railway --debug deploy # Check Railway CLI config railway config # Reset CLI configuration railway config reset ``` ## Advanced Features ### Custom Start Commands ```bash # Set custom start command railway vars set START_COMMAND="node dist/server.js" # Multiple services with different commands railway service create api railway service create worker railway up --service api --start "node api.js" railway up --service worker --start "node worker.js" ``` ### Railway Run Commands ```bash # Execute one-off commands railway run npm install railway run python manage.py migrate railway run bundle exec rake db:migrate # Run with specific environment railway run --environment staging npm test ``` ## Integration Examples ### Next.js Deployment ```bash railway init railway vars set NODE_ENV=production railway vars set NEXT_PUBLIC_API_URL=https://your-app.up.railway.app railway up --start "npm start" ``` ### Docker Deployment ```bash # With custom Dockerfile railway up --dockerfile Dockerfile.prod # With docker-compose (convert to Railway services) railway service create web railway service create db railway add postgresql railway up --service web ```

Install

curl -s https://skills.skynet.ceo/api/skills/railway-cli/skill.md