質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

rbenv

rbenvは、Rubyバージョン管理ツール。プロジェクトごとでRubyバージョンを切り替えることが可能です。RVMよりもシンプルで、少ない機能で動作します。本体にはRubyのビルド機能は備わっておらず、ruby-buildというツールを用いる必要があります。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

1706閲覧

railsアプリの画面がブラウザに表示されなくなった

fugaku

総合スコア0

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

rbenv

rbenvは、Rubyバージョン管理ツール。プロジェクトごとでRubyバージョンを切り替えることが可能です。RVMよりもシンプルで、少ない機能で動作します。本体にはRubyのビルド機能は備わっておらず、ruby-buildというツールを用いる必要があります。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2022/01/16 13:31

①前提・実現したいこと
自作しているrailsアプリケーションをブラウザに表示させたいです。
以前は正常に表示できていたのですが、rbenvでバージョンをいじり始めてから表示されなくなってしまいました。

②使っているツールのバージョンなど補足情報

% ruby --version ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19] % rbenv version 2.7.1 (set by RBENV_VERSION environment variable) % bundler version Bundler version 1.17.2 (2018-12-11 commit 43e950846)
#Gemfile source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.7.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 6.1.3', '>= 6.1.3.2' # Use postgresql as the database for Active Record gem 'pg', '~> 1.1' # Use Puma as the app server gem 'puma', '~> 5.0' # Use SCSS for stylesheets gem 'sass-rails', '>= 6' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 5.0' # 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.7' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password gem 'bcrypt','~>3.1.11' # Use Active Storage variant # gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.4', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 4.1.0' # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md gem 'rack-mini-profiler', '~> 2.0' gem 'listen', '~> 3.3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 3.26' gem 'selenium-webdriver' # Easy installation and use of web drivers to run system tests with browsers gem 'webdrivers' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'dotenv-rails' gem 'devise' gem 'devise-i18n' gem 'devise-i18n-views' gem 'rails-i18n' gem 'order_as_specified' gem 'seed-fu' gem 'bootstrap' gem 'chartkick' gem 'chart-js-rails' gem 'ransack'

③発生している問題
docker-compose up -d でコンテナを起動し、localhostにアクセス
→アプリケーション画面が表示されず、以下のメッセージが表示される。

このサイトにアクセスできません
localhost で接続が拒否されました。
ERR_CONNECTION_REFUSED

④自分で調べたことや試したこと
・webサーバーが起動していないことがわかった。あと、何故かportが表示されていない。

% docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS          NAMES bcf7d01928e7 postgres "docker-entrypoint.s…" 21 minutes ago Up 21 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp portfolio_1_db_1 docker ps -a CONTAINER ID IMAGE              COMMAND CREATED  STATUS                      PORTS                        NAMES 3a8a10849c1d portfolio_1_web "entrypoint.sh bash …" 22 minutes ago Exited (1) 8 minutes ago portfolio_1_web_1 bcf7d01928e7 postgres   "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp portfolio_1_db_1

・Your Ruby version is 2.6.5, but your Gemfile specified 2.7.1と表示されるが、ググっても原因がわからない。

% docker logs -f portfolio_1_db_1 2022-01-16 12:14:56.126 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit 2022-01-16 12:14:56.126 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2022-01-16 12:14:56.126 UTC [1] LOG: listening on IPv6 address "::", port 5432 2022-01-16 12:14:56.131 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2022-01-16 12:14:56.203 UTC [28] LOG: database system was shut down at 2022-01-16 11:53:43 UTC 2022-01-16 12:14:56.247 UTC [1] LOG: database system is ready to accept connections 2022-01-16 12:42:56.227 UTC [32] WARNING: could not open statistics file "pg_stat_tmp/global.stat": Operation not permitted % docker logs -f portfolio_1_web_1 Bundler::RubyVersionMismatch: **Your Ruby version is 2.6.5, but your Gemfile specified 2.7.1** /usr/local/lib/ruby/2.6.0/bundler/definition.rb:495:in `validate_ruby!' /usr/local/lib/ruby/2.6.0/bundler/definition.rb:470:in `validate_runtime!' /usr/local/lib/ruby/2.6.0/bundler.rb:101:in `setup' /usr/local/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>' /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' bundler: failed to load command: rails (/usr/local/bundle/bin/rails) bundler: failed to load command: rails (/usr/local/bundle/bin/rails) Bundler::RubyVersionMismatch: Your Ruby version is 2.6.5, but your Gemfile specified 2.7.1 /usr/local/lib/ruby/2.6.0/bundler/definition.rb:495:in `validate_ruby!' /usr/local/lib/ruby/2.6.0/bundler/definition.rb:470:in `validate_runtime!' /usr/local/lib/ruby/2.6.0/bundler.rb:101:in `setup' /usr/local/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>' /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
% env | grep RBENV_VERSION RBENV_VERSION=2.7.1 #.rbenv/shims/versions 2.7.1 #portfolio_1/.ruby-version 2.7.1
#Dockerfile FROM ruby:2.7.1 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client # yarnパッケージ管理ツールをインストール RUN apt-get update && apt-get install -y curl apt-transport-https wget && \ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt-get update && apt-get install -y yarn # Node.jsをインストール RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - && \ apt-get install nodejs RUN mkdir /portfolio_1 WORKDIR /portfolio_1 COPY Gemfile /portfolio_1/Gemfile COPY Gemfile.lock /portfolio_1/Gemfile.lock RUN bundle install COPY . /portfolio_1 # Add a script to be executed every time the container starts. COPY entrypoint.sh /usr/bin/ RUN chmod +x /usr/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] EXPOSE 3000 # Start the main process. CMD ["rails", "server", "-b", "0.0.0.0"]
#docker-compose.yml version: '3' services: db: image: postgres volumes: - ./tmp/db:/var/lib/postgresql/data ports: - '5432:5432' web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/portfolio_1 ports: - "3000:3000" depends_on: - db

webサーバーが立ち上がればアプリケーション画面が表示されるかと思うのですが・・・。
起動しない原因に心当たりがある方、教えていただきたいです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

docker-compose build
してみたらどうでしょうか?

投稿2022/01/16 17:20

ohoh5454

総合スコア92

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問