##現状
localhost:3000
にアクセスしたらlocalhost で接続が拒否されました。
というエラーが表示されています。
docker初心者ということもあり、色々調べましたが、いまいちピンと来なかった為、再構築を選択しました。
参考にした記事はこちらです。
初めて構築する時も上記の記事を参考に構築しました。
再構築手順は
1. `docker ps` で起動中のコンテナがないか確認。 2. `docker ps -a` でruby2.4とmysql5.7といくつかのnoneのコンテナを`docker rm`コマンドで削除 3. `docker images` でイメージ一覧を表示。先ほど削除したコンテナのイメージを削除 4. `rm -r project` で作成したプロジェクトを削除 5. 参考記事の「Railsアプリケーション用のディレクトリを作成」まで実行し、自身のgithubからプロジェクトをclone 6. clone後、参考記事の「コンテナにRailsアプリを作成」を実行 7. `docker-compose build` を実行 8. `docker-compose up` を実行
になります。
この手順の後、再度localhost:3000
にアクセスしても状況は変わりませんでした。
docker-compose up
後の状況を確認したら、
Starting web-app-sample_db_1 ... done Recreating web-app-sample_web_1 ... done Attaching to web-app-sample_db_1, web-app-sample_web_1 db_1 | 2019-01-07T14:57:34.589678Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). ・ ・ ・
DBの方でかなりエラーが発生しているので、これが原因かなと思っているところなのですが、どう対応すれば良いかわからない為、質問致します。
##質問事項
- 上記のDBのエラーを解消する方法を教えてください
- ブラウザアクセスする為には、DBのエラーを解消すれば解決するのでしょうか?
よろしくお願い致します。
##ログ1
docker-compose.yml
ruby
1version: '3' 2services: 3 db: 4 image: mysql:5.7 5 environment: 6 - MYSQL_ROOT_PASSWORD=password 7 web: 8 build: . 9 command: bundle exec rails s -p 3000 -b '0.0.0.0' 10 volumes: 11 - .:/web-app-sample 12 ports: 13 - "3000:3000" 14 depends_on: 15 - db 16 web: 17 image: nginx:latest 18 ports: 19 - 3000:80
##ログ2
docker-compose.yml
のソースコードが
ruby
1version: '2' 2services: 3 db: 4 image: mysql:5.7 5 environment: 6 - MYSQL_ROOT_PASSWORD=password 7 web: 8 build: . 9 command: bundle exec rails s -p 3000 -b '0.0.0.0' 10 volumes: 11 - .:/web-app-sample 12 ports: 13 - "3000:3000" 14 depends_on: 15 - db
の状態でdocker-compose exec web /bin/bash
を実行したらERROR: No container found for web_1
というエラーが発生。
docker ps
で起動中のコンテナを確認したら、mysqlのみ
なぜかwebの方が起動しない。理由不明。/bin/bashに入れないので、Logも確認できず。
ログ1
のNginxのimageを記載して、再度docker-compose exec web /bin/bash
を実行したら入れた。
入れたがNginxが起動しているのと、Nginxの初期画面が表示されているので、errorログは出ず、論点からもずれ
##ログ3
docker-compose up
実行後のwebの状態
web_1 | bundler: failed to load command: rails (/usr/local/bundle/bin/rails) web_1 | Bundler::LockfileError: You must use Bundler 2 or greater with this lockfile. web_1 | /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version' web_1 | /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/lockfile_parser.rb:95:in `initialize' web_1 | /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/definition.rb:72:in `new' ・ ・ ・
##ログ4
Dockerfile
FROM ruby:2.4.0 ENV LANG C.UTF-8 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN gem install bundler WORKDIR /tmp ADD Gemfile Gemfile ADD Gemfile.lock Gemfile.lock RUN bundle install ENV APP_HOME /web-app-sample RUN mkdir -p $APP_HOME WORKDIR $APP_HOME ADD . $APP_HOME
##ログ5
docker-compose up
<master>tto8569:web-app-sample$ docker-compose up Starting web-app-sample_db_1 ... done Starting web-app-sample_web_1 ... done Attaching to web-app-sample_db_1, web-app-sample_web_1 db_1 | 2019-01-10T05:03:09.992503Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). db_1 | 2019-01-10T05:03:09.993695Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ... db_1 | 2019-01-10T05:03:09.996189Z 0 [Note] InnoDB: PUNCH HOLE support available db_1 | 2019-01-10T05:03:09.996224Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins db_1 | 2019-01-10T05:03:09.996231Z 0 [Note] InnoDB: Uses event mutexes db_1 | 2019-01-10T05:03:09.996237Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier db_1 | 2019-01-10T05:03:09.996242Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 db_1 | 2019-01-10T05:03:09.996247Z 0 [Note] InnoDB: Using Linux native AIO db_1 | 2019-01-10T05:03:09.996431Z 0 [Note] InnoDB: Number of pools: 1 db_1 | 2019-01-10T05:03:09.996511Z 0 [Note] InnoDB: Using CPU crc32 instructions db_1 | 2019-01-10T05:03:09.997929Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M db_1 | 2019-01-10T05:03:10.005073Z 0 [Note] InnoDB: Completed initialization of buffer pool db_1 | 2019-01-10T05:03:10.006796Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). db_1 | 2019-01-10T05:03:10.018033Z 0 [Note] InnoDB: Highest supported file format is Barracuda. db_1 | 2019-01-10T05:03:10.028264Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables db_1 | 2019-01-10T05:03:10.028329Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... db_1 | 2019-01-10T05:03:10.053855Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. db_1 | 2019-01-10T05:03:10.054645Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
##ログ6
development.log
Started GET "/" for 172.20.0.1 at 2019-01-10 09:29:06 +0000 Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 ActiveRecord::NoDatabaseError (Unknown database 'web-app-sample_development'): activerecord (5.2.2) lib/active_record/connection_adapters/mysql2_adapter.rb:26:in `rescue in mysql2_connection' activerecord (5.2.2) lib/active_record/connection_adapters/mysql2_adapter.rb:12:in `mysql2_connection' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection' activerecord (5.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:1010:in `retrieve_connection' activerecord (5.2.2) lib/active_record/connection_handling.rb:118:in `retrieve_connection' activerecord (5.2.2) lib/active_record/connection_handling.rb:90:in `connection' activerecord (5.2.2) lib/active_record/migration.rb:554:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' activesupport (5.2.2) lib/active_support/callbacks.rb:98:in `run_callbacks' actionpack (5.2.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call' web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app' web-console (3.7.0) lib/web_console/middleware.rb:22:in `block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch' web-console (3.7.0) lib/web_console/middleware.rb:20:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' railties (5.2.2) lib/rails/rack/logger.rb:38:in `call_app' railties (5.2.2) lib/rails/rack/logger.rb:26:in `block in call' activesupport (5.2.2) lib/active_support/tagged_logging.rb:71:in `block in tagged' activesupport (5.2.2) lib/active_support/tagged_logging.rb:28:in `tagged' activesupport (5.2.2) lib/active_support/tagged_logging.rb:71:in `tagged' railties (5.2.2) lib/rails/rack/logger.rb:26:in `call' sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/request_id.rb:27:in `call' rack (2.0.6) lib/rack/method_override.rb:22:in `call' rack (2.0.6) lib/rack/runtime.rb:22:in `call' activesupport (5.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/executor.rb:14:in `call' actionpack (5.2.2) lib/action_dispatch/middleware/static.rb:127:in `call' rack (2.0.6) lib/rack/sendfile.rb:111:in `call' railties (5.2.2) lib/rails/engine.rb:524:in `call' puma (3.12.0) lib/puma/configuration.rb:225:in `call' puma (3.12.0) lib/puma/server.rb:658:in `handle_request' puma (3.12.0) lib/puma/server.rb:472:in `process_client' puma (3.12.0) lib/puma/server.rb:332:in `block in run' puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
docker-compose run web rake db:create
の実行結果
$ docker-compose run web rake db:create Starting web-app-sample_db_1 ... done You must use Bundler 2 or greater with this lockfile.
回答2件
あなたの回答
tips
プレビュー