前提・実現したいこと
現在、ポートフォリオ作成のための掲示板アプリのようなものを製作しています。
先日まではCloud9上で開発を行なっていたのですが、環境構築の勉強と色んな技術に触れてみたいと思い、Dockerを用いてローカル環境での開発に取り組みはじめました。
アプリはすでにherokuを用いて公開していたのでheroku masterからpullを行いデータを持ってきてそこにDockerfile、docker-compose.ymlを作成する形で環境構築を行なっています。
参考にしたのは以下のサイトです。
Docker+MySQL+Railsの環境構築
既存のRailsアプリにDockerを導入する手順
発生している問題・エラーメッセージ
このページの流れに従ってdocker-compose build
を行い、docker-compose up
までは無事行うことができたのですが、docker-compose run web rails db:create
を行う際にエラーが発生しました。ターミナルの実行結果は以下の通りです
Terminal
1$ docker-compose run web rails db:create 2Starting my-app_db_1 ... done 3rails aborted! 4ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["default"] 5/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/connection_specification.rb:260:in `resolve_symbol_connection' 6/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/connection_specification.rb:241:in `resolve_connection' 7/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/connection_specification.rb:143:in `resolve' 8/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:57:in `establish_connection' 9/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/railtie.rb:136:in `block (2 levels) in <class:Railtie>' 10/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval' 11/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook' 12/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control' 13/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook' 14/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks' 15/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in `each' 16/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks' 17/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/base.rb:328:in `<module:ActiveRecord>' 18/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/base.rb:27:in `<main>' 19/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require' 20/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi' 21/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 22/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi' 23/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' 24/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require' 25/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' 26/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require' 27/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <main>' 28/usr/local/bundle/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' 29/usr/local/bundle/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform' 30/usr/local/bundle/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke' 31/usr/local/bundle/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>' 32/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require' 33/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi' 34/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' 35/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi' 36/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' 37/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require' 38/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' 39/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require' 40/app_name/bin/rails:9:in `<top (required)>' 41/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load' 42/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call' 43/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call' 44/usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run' 45/usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>' 46/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load' 47/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>' 48/app_name/bin/spring:15:in `<top (required)>' 49bin/rails:3:in `load' 50bin/rails:3:in `<main>' 51Tasks: TOP => db:create => db:load_config 52(See full trace by running task with --trace)
関連するソースコード
databaseyml
1default: &default 2 adapter: mysql2 3 encoding: utf8 4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 5 username: root 6 password: password 7 host: db # docker-compose.ymlのservice名 8 9development: 10 <<: *default 11 database: myproject_development
*修正
RUN mkdir /workdir
ENV APP_ROOT /app-name
↓
RUN mkdir /my-app
ENV APP_ROOT /my-app
Dockerfile
1FROM ruby:2.6.3 2ENV ruby_ver="2.4.3" 3ENV rails_ver="5.2.3" 4RUN apt-get update -qq && \ 5 apt-get install -y build-essential \ 6 libpq-dev \ 7 nodejs 8 9RUN mkdir /my-app 10ENV APP_ROOT /my-app 11WORKDIR $APP_ROOT 12 13COPY ./Gemfile $APP_ROOT/Gemfile 14COPY ./Gemfile.lock $APP_ROOT/Gemfile.lock 15 16RUN gem install bundler:2.0.2 17RUN bundle install 18COPY . $APP_ROOT
dockercomposeyml
1version: '3' 2services: 3 db: 4 image: mysql:5.7 5 environment: 6 MYSQL_ROOT_PASSWORD: password 7 MYSQL_DATABASE: root 8 ports: 9 - "3306:3306" 10 11 web: 12 build: . 13 command: bundle exec rails s -p 3000 -b '0.0.0.0' 14 volumes: 15 - .:/my-app 16 ports: 17 - "3000:3000" 18 links: 19 - db:mysql
試したこと
Terminalの実行結果にActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["default"]
とあるようにdevelopment環境での設定に問題がありそうだと思い、database.ymlの設定を調べながら色々変更してみたのですが、解決には至りませんでした。
経験が浅いため原因の見当もつかなくて申し訳ないです,,,
追記してほしい情報などあればコメントください。
回答1件
あなたの回答
tips
プレビュー