< 前提・実現したい>
docker-compose psをした際にWebコンテナのstatusがExit1なっているため、
localhost:3000にアクセスしても表示されない問題を解決したい
<詳細>
Dockerfile,Gemfile,Gemfile.lock,docker-compose.yml(コードは後述)を用意し、
①docker-compose run web rails new . --forcee --database=mysql
②docker-compose build
③docker-compose up -d
をし、ひとまず、ページにアクセスしたい
<発生している問題・エラーメッセージ>
statusがExit1になり起動しない
tochikawa@tochinoMacBook-Pro docker-files % docker-compose ps Name Command State Ports ---------------------------------------------------------------------------------- docker-files_db_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp docker-files_web_1 bundle exec rails s -p 300 ... Exit 1
該当のソースコード
<Dockerfile> ```ここに言語を入力 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 COPY . /app<Gemfile> ```ここに言語を入力 source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' # Use mysql as the database for Active Record gem 'mysql2', '>= 0.3.18', '< 0.5' # Use Puma as the app server gem 'puma', '~> 3.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' gem 'bootstrap', '~>4.0.0' gem 'mini_racer' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console' gem 'listen', '~> 3.0.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' gem 'pry-byebug' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
<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:
試したこと
一旦、docker-compose stopをしてコンテナの削除を試み、再度docker-compose up -dをしたが、治らず。
今度は、docker-compose downにてコンテナを削除し
①docker-compose run web rails new . --forcee --database=mysql
②docker-compose build
③docker-compose up -d
そのあと、docker-compose down --rmi all
をして、再度上記を行うも治らず。
また、log以下のようになる
docker-compose logs web Attaching to docker-files_web_1 web_1 | => Booting Puma web_1 | => Rails 5.0.7.2 application starting in development on http://0.0.0.0:3000 web_1 | => Run `rails server -h` for more startup options web_1 | Exiting web_1 | /app/config/routes.rb:4:in `block in <top (required)>': undefined method `resorces' for #<ActionDispatch::Routing::Mapper:0x000055c563ed8680> (NoMethodError) web_1 | from /usr/local/bundle/gems/actionpack-5.0.7.2/lib/action_dispatch/routing/route_set.rb:391:in `instance_exec' web_1 | from /usr/local/bundle/gems/actionpack-5.0.7.2/lib/action_dispatch/routing/route_set.rb:391:in `eval_block' web_1 | from /usr/local/bundle/gems/actionpack-5.0.7.2/lib/action_dispatch/routing/route_set.rb:373:in `draw' web_1 | from /app/config/routes.rb:1:in `<top (required)>' web_1 | from /usr/local/bundle/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load' web_1 | from /usr/local/bundle/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `block in load' web_1 | from /usr/local/bundle/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency' web_1 | from /usr/local/bundle/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:40:in `each' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:40:in `load_paths' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:16:in `reload!' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:26:in `block in updater' web_1 | from /usr/local/bundle/gems/activesupport-5.0.7.2/lib/active_support/file_update_checker.rb:77:in `execute' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:27:in `updater' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application/finisher.rb:119:in `block in <module:Finisher>' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `instance_exec' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `run' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/initializable.rb:55:in `block in run_initializers' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:347:in `each' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:347:in `call' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each' web_1 | from /usr/local/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/initializable.rb:54:in `run_initializers' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/application.rb:352:in `initialize!' web_1 | from /app/config/environment.rb:5:in `<top (required)>' web_1 | from /app/config.ru:3:in `require_relative' web_1 | from /app/config.ru:3:in `block in <main>' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:249:in `app' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/server.rb:84:in `app' web_1 | from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/server.rb:148:in `log_to_stdout' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/server.rb:102:in `start' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:90:in `block in server' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:85:in `tap' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:85:in `server' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!' web_1 | from /usr/local/bundle/gems/railties-5.0.7.2/lib/rails/commands.rb:18:in `<top (required)>' web_1 | from /app/bin/rails:9:in `require' web_1 | from /app/bin/rails:9:in `<top (required)>' web_1 | from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load' web_1 | from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call' web_1 | from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call' web_1 | from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client.rb:30:in `run' web_1 | from /usr/local/bundle/gems/spring-2.1.1/bin/spring:49:in `<top (required)>' web_1 | from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load' web_1 | from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>' web_1 | from /app/bin/spring:15:in `require' web_1 | from /app/bin/spring:15:in `<top (required)>' web_1 | from bin/rails:3:in `load' web_1 | from bin/rails:3:in `<main>'
それでも治らず。
初心者ゆえできればわかりやすく解説していただけると幸いです
よろしくお願いします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/02/26 00:22