0
0

More than 3 years have passed since last update.

rails5+MysqlをDocker-composeにてherokuにデプロイする際のエラー

Posted at

udemyのこちら
https://www.udemy.com/course/rails-kj/
を学習中

SNS掲示板アプリ
を作らせてもらっている。

Rails 5系
Ruby 2.4.5
mysql2

最後にherokuにデプロイしようとおもって

Rails on DockerをHerokuでDeployするまで
HerokuでMySQLを使おうとして詰まったところ
を参考にして、トライ

流れとしては、
clearDBをアドオンとして追加
configに設定(mysql2に変更)
heroku CLIログイン
heroku containerにログイン
heroku create~~
heroku container:push web
heroku container:release web
heroku run rails db:migrate
heroku open
heroku run rails assets:precompile
heroku config:add RAILS_ENV=production
(アセットパイプライン関連は理解がおいついていない)

しかし、heroku openにてApplication errorとなり、
heroku logs --tailにて

2020-08-31T00:05:17.338031+00:00 app[api]: Deployed web (09d5e5e0baba) by user shutainer@yahoo.co.jp
2020-08-31T00:05:17.338031+00:00 app[api]: Release v14 created by user shutainer@yahoo.co.jp
2020-08-31T00:05:17.566831+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-31T00:05:33.102257+00:00 app[api]: Starting process with command `rails db:migrate` by user shutainer@yahoo.co.jp
2020-08-31T00:05:41.271963+00:00 heroku[web.1]: Starting process with command `irb`
2020-08-31T00:05:44.759411+00:00 app[web.1]: Switch to inspect mode.
2020-08-31T00:05:44.760171+00:00 app[web.1]: 
2020-08-31T00:05:44.815317+00:00 heroku[web.1]: Process exited with status 0
2020-08-31T00:05:44.849695+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-31T00:05:44.852418+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-31T00:05:52.851790+00:00 heroku[run.7980]: State changed from starting to up
2020-08-31T00:05:52.856447+00:00 heroku[run.7980]: Awaiting client
2020-08-31T00:05:52.891424+00:00 heroku[run.7980]: Starting process with command `rails db:migrate`
2020-08-31T00:05:59.894902+00:00 heroku[run.7980]: Process exited with status 0
2020-08-31T00:05:59.927380+00:00 heroku[run.7980]: State changed from up to complete
2020-08-31T00:06:05.419295+00:00 heroku[web.1]: Starting process with command `irb`
2020-08-31T00:06:08.786074+00:00 app[web.1]: Switch to inspect mode.
2020-08-31T00:06:08.786799+00:00 app[web.1]: 
2020-08-31T00:06:08.879555+00:00 heroku[web.1]: Process exited with status 0
2020-08-31T00:06:08.991140+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-31T00:09:58.194158+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-temple-79557.herokuapp.com request_id=432296e9-7359-4456-bbc2-b885e514a27d fwd="111.97.175.96" dyno= connect= service= status=503 bytes= protocol=https
2020-08-31T00:09:59.223351+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-temple-79557.herokuapp.com request_id=12c8e692-769d-45a7-9967-ce77256746eb fwd="111.97.175.96" dyno= connect= service= status=503 bytes= protocol=https

と出てしまった。

さらに、
heroku run rails console cすると、

Running via Spring preloader in process 18
WARNING: Spring is running in production. To fix this make sure the spring gem is only present in `development` and `test` groups in your Gemfile and make sure you always use `bundle install --without development test` in production
Loading production environment (Rails 5.0.7.2)

そのため、
Dockerfileでbundle installを変えて

FROM ruby:2.4.5
RUN apt-get update -qq && apt-get install -y build-essential nodejs
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install --without development test
COPY . /app

と書き換えたが、治らず。

うーん弱った、、、

以下Docker-compose.yml

Docker-compose.yml
version: '3'
services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - 3000:3000
    depends_on:
      - db
    tty: true
    stdin_open: true
  db:
    image: mysql:5.7
    volumes:
      - db-volume:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
volumes:
  db-volume:
0
0
1

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
0
0