5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerでherokuにデプロイ(Rails6、MySQL)

Last updated at Posted at 2020-11-13

#1 前提条件
1 クレジットカード登録済みのherokuアカウント
2 docker環境で作成したRailsアプリ(credentials:editを編集する場合はDockerfileにRUN apt-get install -y vimを追加) *こちらの記事を参考https://qiita.com/croquette0212/items/44378e01de18f62d01df
3 heroku cliインストール済み

#2 config/environments/development.rbに下記を記載

Rails.application.confiture do
(略)
config.hosts.clear
(略)
end 

#3 コンテナ停止&server.pidを削除

$ docker-compose stop
$ rm -f tmp/pids/server.pid

#4 heroku準備 

$ cd ディレクトリ名
$ heroku login --interactive
$ heroku container:login 
$ heroku create アプリ名

#5 herokuのデータベース設定をMySQLに変更

$ heroku addons:add cleardb
$ heroku config:set DATABASE_URL=`heroku config:get CLEARDB_DATABASE_URL | sed -- s/mysql/mysql2/`

#6 herokuにデプロイ
*heroku container:release webの前にheroku run rails db:migrateをするとbash: rails: command not foundのエラーが出ることがあるようです。

$ heroku container:push web
$ heroku container:release web
$ heroku run rails db:migrate
$ heroku open
5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?