コンテンツにスキップ

Heroku CLI

Comprehensive Heroku CLI commands and workflows for deploying and managing applications on the Heroku platform.

Installation & Authentication

Command Description
heroku login Login to Heroku
heroku login -i Login interactively
heroku logout Logout from Heroku
heroku auth:whoami Show current user
heroku auth:token Display auth token

App Management

Basic App Operations

Command Description
heroku apps List all apps
heroku apps:create myapp Create new app
heroku apps:destroy myapp Delete app
heroku apps:info Show app info
heroku apps:rename newname Rename app
heroku apps:open Open app in browser

App Configuration

Command Description
heroku config Show config vars
heroku config:set KEY=value Set config var
heroku config:unset KEY Remove config var
heroku config:get KEY Get specific config var
heroku buildpacks List buildpacks
heroku buildpacks:set heroku/nodejs Set buildpack

Deployment

Git Deployment

Command Description
git push heroku main Deploy from main branch
git push heroku develop:main Deploy from develop branch
heroku git:remote -a myapp Add Heroku remote
heroku releases List releases
heroku releases:rollback v123 Rollback to specific release

Container Deployment

Command Description
heroku container:login Login to container registry
heroku container:push web Build and push container
heroku container:release web Release container
heroku container:rm web Remove container

Dynos and Scaling

Dyno Management

Command Description
heroku ps List dynos
heroku ps:scale web=2 Scale web dynos
heroku ps:scale worker=1 Scale worker dynos
heroku ps:restart Restart all dynos
heroku ps:restart web.1 Restart specific dyno
heroku ps:stop web.1 Stop specific dyno

Dyno Types

Command Description
heroku ps:type Show dyno types
heroku ps:resize web=standard-1x Resize dyno type
heroku ps:exec SSH into dyno

Add-ons

Add-on Management

Command Description
heroku addons List app add-ons
heroku addons:create heroku-postgresql Add PostgreSQL
heroku addons:create heroku-redis Add Redis
heroku addons:destroy ADDON_NAME Remove add-on
heroku addons:upgrade ADDON_NAME:PLAN Upgrade add-on plan
heroku addons:downgrade ADDON_NAME:PLAN Downgrade add-on plan
Command Description
heroku addons:create sendgrid Add SendGrid email
heroku addons:create papertrail Add Papertrail logging
heroku addons:create newrelic Add New Relic monitoring
heroku addons:create scheduler Add Heroku Scheduler

Database Operations

PostgreSQL

Command Description
heroku pg List PostgreSQL databases
heroku pg:info Show database info
heroku pg:psql Connect to database
heroku pg:reset DATABASE_URL Reset database
heroku pg:backups List backups
heroku pg:backups:capture Create backup
heroku pg:backups:restore BACKUP_URL DATABASE_URL Restore backup

Database Maintenance

Command Description
heroku pg:maintenance Show maintenance info
heroku pg:maintenance:run Run maintenance
heroku pg:stats Show database stats
heroku pg:diagnose Diagnose database issues

Logging and Monitoring

Logs

Command Description
heroku logs Show recent logs
heroku logs --tail Stream logs
heroku logs --source app Show app logs only
heroku logs --dyno web.1 Show specific dyno logs
heroku logs --num 1000 Show more log lines

Monitoring

Command Description
heroku ps:autoscale:enable Enable autoscaling
heroku ps:autoscale:disable Disable autoscaling
heroku metrics Show app metrics

Domains and SSL

Domain Management

Command Description
heroku domains List domains
heroku domains:add example.com Add custom domain
heroku domains:remove example.com Remove domain
heroku domains:info example.com Show domain info

SSL Certificates

Command Description
heroku certs List SSL certificates
heroku certs:add cert.pem key.pem Add SSL certificate
heroku certs:remove Remove SSL certificate
heroku certs:auto:enable Enable automatic SSL
heroku certs:auto:disable Disable automatic SSL

Pipelines and Review Apps

Pipeline Management

Command Description
heroku pipelines List pipelines
heroku pipelines:create mypipeline Create pipeline
heroku pipelines:destroy mypipeline Delete pipeline
heroku pipelines:add mypipeline --stage staging Add app to pipeline
heroku pipelines:remove Remove app from pipeline

Promotions

Command Description
heroku pipelines:promote --remote staging Promote to production
heroku releases:rollback --remote production Rollback production

Review Apps

Command Description
heroku reviewapps:enable Enable review apps
heroku reviewapps:disable Disable review apps

Teams and Collaboration

Team Management

Command Description
heroku teams List teams
heroku members List team members
heroku members:add user@example.com Add team member
heroku members:remove user@example.com Remove team member

Access Control

Command Description
heroku access List app collaborators
heroku access:add user@example.com Add collaborator
heroku access:remove user@example.com Remove collaborator

CLI Plugins

Plugin Management

Command Description
heroku plugins List installed plugins
heroku plugins:install PLUGIN_NAME Install plugin
heroku plugins:uninstall PLUGIN_NAME Uninstall plugin
heroku plugins:update Update all plugins
Command Description
heroku plugins:install heroku-repo Install repo plugin
heroku repo:reset Reset git repository
heroku repo:purge_cache Purge build cache

Environment Management

Multiple Environments

Command Description
heroku git:remote -a myapp-staging -r staging Add staging remote
heroku git:remote -a myapp-production -r production Add production remote
git push staging main Deploy to staging
git push production main Deploy to production

Environment Variables

Command Description
heroku config --remote staging Show staging config
heroku config:set NODE_ENV=production --remote production Set production config

Maintenance and Troubleshooting

Maintenance Mode

Command Description
heroku maintenance:on Enable maintenance mode
heroku maintenance:off Disable maintenance mode
heroku maintenance Check maintenance status

Troubleshooting

Command Description
heroku run bash Run bash shell
heroku run rails console Run Rails console
heroku run python manage.py shell Run Django shell
heroku run node Run Node.js REPL

Performance

Command Description
heroku labs:enable preboot Enable preboot
heroku labs:disable preboot Disable preboot
heroku ps:wait Wait for dyno to be ready

Best Practices

Deployment

  1. Use Pipelines: Set up staging and production environments
  2. Environment Variables: Store configuration in config vars
  3. Database Migrations: Run migrations during deployment
  4. Health Checks: Implement health check endpoints

Security

  1. SSL: Always use SSL for production apps
  2. Environment Separation: Keep staging and production separate
  3. Access Control: Limit collaborator access
  4. Secrets Management: Use config vars for sensitive data

Performance

  1. Dyno Sizing: Choose appropriate dyno types
  2. Caching: Implement caching strategies
  3. Database Optimization: Monitor and optimize database queries
  4. CDN: Use CDN for static assets

Monitoring

  1. Logging: Implement comprehensive logging
  2. Metrics: Monitor application metrics
  3. Alerts: Set up alerts for critical issues
  4. Error Tracking: Use error tracking services