macOS 10.12.6で,Railsアプリを作っています.開発環境ではdocker(Docker version 18.03.1-ce, build 9ee9f40
)を使っていて,次のようなDockerfile
です:
FROM ruby:2.5.0 ENV APP_ROOT /usr/src/naughie WORKDIR $APP_ROOT RUN apt-get update && \ apt-get install -y nodejs \ mysql-client \ postgresql-client \ sqlite3 \ vim \ --no-install-recommends && \ rm -rf /var/lib/apt/lists/* COPY Gemfile $APP_ROOT COPY Gemfile.lock $APP_ROOT COPY .pryrc $APP_ROOT RUN \ echo 'gem: --no-document' >> ~/.gemrc && \ cp ~/.gemrc /etc/gemrc && \ chmod uog+r /etc/gemrc && \ bundle config --global build.nokogiri --use-system-libraries && \ bundle config --global jobs 4 && \ bundle config --global path /bundle && \ bundle install && \ rm -rf ~/.gem COPY . $APP_ROOT CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
は,
version: '2' services: db: image: postgres ports: - '5432' volumes: - postgres-data:/data redis: image: redis:latest ports: - '6379:6379' volumes: - redis-data:/redis web: build: . environment: EDITOR: vim RAILS_ENV: development DATABASE_USER: postgres DATABASE_PASSWORD: password DATABASE_PORT: 5432 DATABASE_HOST: db REDIS_URL: redis://redis:6379 ports: - '3000:3000' volumes: - .:/usr/src/app_name - bundle-data:/bundle links: - db - redis volumes: bundle-data: driver: local postgres-data: driver: local redis-data: driver: local
です.プロジェクトはGithubで管理しています.
これでdocker-compose build
,docker-compose up
とすれば正常に動きます(動いていると思っています).
次に,Herokuで動かすために以下の手順に従いました(主にこの記事を参考にしています):
heroku login
,heroku container:login
;heroku plugins:install heroku-container-registry
;heroku create $APP_NAME
;heroku container:push web
;- Herokuのアドオンpostgreを追加,及び環境変数を設定;
heroku run rake db:migrate
.
しかし,heroku run rake db:migrate
で以下のエラーが出てしまいます:
$ heroku run rake db:migrate Running rake db:migrate --trace on ⬢ my_app... up, run.7115 (Free) rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /usr/lib/ruby/vendor_ruby/rake/application.rb:684:in `raw_load_rakefile' /usr/lib/ruby/vendor_ruby/rake/application.rb:94:in `block in load_rakefile' /usr/lib/ruby/vendor_ruby/rake/application.rb:176:in `standard_exception_handling' /usr/lib/ruby/vendor_ruby/rake/application.rb:93:in `load_rakefile' /usr/lib/ruby/vendor_ruby/rake/application.rb:77:in `block in run' /usr/lib/ruby/vendor_ruby/rake/application.rb:176:in `standard_exception_handling' /usr/lib/ruby/vendor_ruby/rake/application.rb:75:in `run' /usr/bin/rake:27:in `<main>'
実際,heroku run ls -a
で確認してみると空のディレクトリになっているので,containerの中ではなくこちらを参照してしまっているのだと思います.また試しにheroku open
としても,Herokuのデフォルトページが表示されるだけです.
調べてみると,VOLUMEが使えないと書いてあるのでdocker-compose.yml
のvolumes
以下がいけないのでしょうか.もしそうなら,どのようにすればよいのでしょうか.
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。