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

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

新規登録して質問してみよう
ただいま回答率
85.51%
Next.js

Next.jsは、Reactを用いたサーバサイドレンダリングなどを行う軽量なフレームワークです。Zeit社が開発しており、nextコマンドでプロジェクトを作成することにより、開発環境整備が整った環境が即時に作成できます。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

753閲覧

Rails7系/Next.js/MySQLをDockerで起動したい

kaze0000

総合スコア15

Next.js

Next.jsは、Reactを用いたサーバサイドレンダリングなどを行う軽量なフレームワークです。Zeit社が開発しており、nextコマンドでプロジェクトを作成することにより、開発環境整備が整った環境が即時に作成できます。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

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

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2022/07/22 14:03

前提

Dockerfileやdocker-composse.ymlの記載内容が間違っている可能性もあり、
その点も確認いただけると幸いです。

実現したいこと

  • Rails7系 Next.js MySQLをDockerで起動したい

発生している問題・エラーメッセージ

  • まず、ルートディレクトリで docker-compose upをします。

イメージ説明

  • localhost:8000に移動すると、Next.jsは起動し、welcome to next.js が出現します
  • ですが、localhost:3000に移動すると、「このサイトにアクセスできません」となります。
  • docker compose up した際にターミナルには以下のようなエラーが表記されています。
Could not find mysql2-0.5.4, puma-5.6.4, bootsnap-1.12.0, debug-1.6.1, msgpack-1.5.3, reline-0.3.1 in any of the sources api_1 | Run `bundle install` to install missing gems.

該当のソースコード

docker-compose.yml

ruby

1version: "3.7" 2 3services: 4 db: 5 image: mysql:5.7 6 environment: 7 MYSQL_ROOT_PASSWORD: password 8 MYSQL_DATABASE: root 9 ports: 10 - "3306:3306" 11 volumes: 12 - ./tmp/db:/var/lib/mysql 13 14 api: 15 tty: true 16 depends_on: 17 - db 18 build: 19 context: ./api/ 20 dockerfile: Dockerfile 21 ports: 22 - 3000:3000 23 volumes: 24 - ./api:/app 25 command: rails server -b 0.0.0.0 26 27 front: 28 build: 29 context: ./front/ 30 dockerfile: Dockerfile 31 volumes: 32 - ./front/app:/usr/src/app 33 command: "yarn dev" 34 ports: 35 - "8000:3000"

front/Dockerfile

ruby

1FROM node:14-alpine 2WORKDIR /usr/src/app

api/Dockerfile

ruby

1FROM ruby:3.1.1 2RUN apt-get update && apt-get install -y curl apt-transport-https wget && \ 3curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ 4echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ 5apt-get update && apt-get install -y yarn 6WORKDIR /app 7COPY Gemfile /app/Gemfile 8COPY Gemfile.lock /app/Gemfile.lock 9RUN bundle install 10 11# Add a script to be executed every time the container starts. 12COPY entrypoint.sh /usr/bin/ 13RUN chmod +x /usr/bin/entrypoint.sh 14ENTRYPOINT ["entrypoint.sh"] 15EXPOSE 3000 16 17# Configure the main process to run when running the image 18CMD ["rails", "server", "-b", "0.0.0.0"]

Gemfile

ruby

1source "https://rubygems.org" 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby "3.1.1" 5 6# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7gem "rails", "~> 7.0.3", ">= 7.0.3.1" 8 9# Use mysql as the database for Active Record 10gem "mysql2", "~> 0.5" 11 12# Use the Puma web server [https://github.com/puma/puma] 13gem "puma", "~> 5.0" 14 15# Build JSON APIs with ease [https://github.com/rails/jbuilder] 16# gem "jbuilder" 17 18# Use Redis adapter to run Action Cable in production 19# gem "redis", "~> 4.0" 20 21# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 22# gem "kredis" 23 24# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 25# gem "bcrypt", "~> 3.1.7" 26 27# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 28gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 29 30# Reduces boot times through caching; required in config/boot.rb 31gem "bootsnap", require: false 32 33# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 34# gem "image_processing", "~> 1.2" 35 36# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible 37# gem "rack-cors" 38 39group :development, :test do 40 # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 41 gem "debug", platforms: %i[ mri mingw x64_mingw ] 42end 43 44group :development do 45 # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 46 # gem "spring" 47end

Gemfile.lock

ruby

1GEM 2 remote: https://rubygems.org/ 3 specs: 4 actioncable (7.0.3.1) 5 actionpack (= 7.0.3.1) 6 activesupport (= 7.0.3.1) 7 nio4r (~> 2.0) 8 websocket-driver (>= 0.6.1) 9 actionmailbox (7.0.3.1) 10 actionpack (= 7.0.3.1) 11 activejob (= 7.0.3.1) 12 activerecord (= 7.0.3.1) 13 activestorage (= 7.0.3.1) 14 activesupport (= 7.0.3.1) 15 mail (>= 2.7.1) 16 net-imap 17 net-pop 18 net-smtp 19 actionmailer (7.0.3.1) 20 actionpack (= 7.0.3.1) 21 actionview (= 7.0.3.1) 22 activejob (= 7.0.3.1) 23 activesupport (= 7.0.3.1) 24 mail (~> 2.5, >= 2.5.4) 25 net-imap 26 net-pop 27 net-smtp 28 rails-dom-testing (~> 2.0) 29 actionpack (7.0.3.1) 30 actionview (= 7.0.3.1) 31 activesupport (= 7.0.3.1) 32 rack (~> 2.0, >= 2.2.0) 33 rack-test (>= 0.6.3) 34 rails-dom-testing (~> 2.0) 35 rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 actiontext (7.0.3.1) 37 actionpack (= 7.0.3.1) 38 activerecord (= 7.0.3.1) 39 activestorage (= 7.0.3.1) 40 activesupport (= 7.0.3.1) 41 globalid (>= 0.6.0) 42 nokogiri (>= 1.8.5) 43 actionview (7.0.3.1) 44 activesupport (= 7.0.3.1) 45 builder (~> 3.1) 46 erubi (~> 1.4) 47 rails-dom-testing (~> 2.0) 48 rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 activejob (7.0.3.1) 50 activesupport (= 7.0.3.1) 51 globalid (>= 0.3.6) 52 activemodel (7.0.3.1) 53 activesupport (= 7.0.3.1) 54 activerecord (7.0.3.1) 55 activemodel (= 7.0.3.1) 56 activesupport (= 7.0.3.1) 57 activestorage (7.0.3.1) 58 actionpack (= 7.0.3.1) 59 activejob (= 7.0.3.1) 60 activerecord (= 7.0.3.1) 61 activesupport (= 7.0.3.1) 62 marcel (~> 1.0) 63 mini_mime (>= 1.1.0) 64 activesupport (7.0.3.1) 65 concurrent-ruby (~> 1.0, >= 1.0.2) 66 i18n (>= 1.6, < 2) 67 minitest (>= 5.1) 68 tzinfo (~> 2.0) 69 bootsnap (1.12.0) 70 msgpack (~> 1.2) 71 builder (3.2.4) 72 concurrent-ruby (1.1.10) 73 crass (1.0.6) 74 debug (1.6.1) 75 irb (>= 1.3.6) 76 reline (>= 0.3.1) 77 digest (3.1.0) 78 erubi (1.10.0) 79 globalid (1.0.0) 80 activesupport (>= 5.0) 81 i18n (1.12.0) 82 concurrent-ruby (~> 1.0) 83 io-console (0.5.11) 84 irb (1.4.1) 85 reline (>= 0.3.0) 86 loofah (2.18.0) 87 crass (~> 1.0.2) 88 nokogiri (>= 1.5.9) 89 mail (2.7.1) 90 mini_mime (>= 0.1.1) 91 marcel (1.0.2) 92 method_source (1.0.0) 93 mini_mime (1.1.2) 94 minitest (5.16.2) 95 msgpack (1.5.3) 96 mysql2 (0.5.4) 97 net-imap (0.2.3) 98 digest 99 net-protocol 100 strscan 101 net-pop (0.1.1) 102 digest 103 net-protocol 104 timeout 105 net-protocol (0.1.3) 106 timeout 107 net-smtp (0.3.1) 108 digest 109 net-protocol 110 timeout 111 nio4r (2.5.8) 112 nokogiri (1.13.7-x86_64-linux) 113 racc (~> 1.4) 114 puma (5.6.4) 115 nio4r (~> 2.0) 116 racc (1.6.0) 117 rack (2.2.4) 118 rack-test (2.0.2) 119 rack (>= 1.3) 120 rails (7.0.3.1) 121 actioncable (= 7.0.3.1) 122 actionmailbox (= 7.0.3.1) 123 actionmailer (= 7.0.3.1) 124 actionpack (= 7.0.3.1) 125 actiontext (= 7.0.3.1) 126 actionview (= 7.0.3.1) 127 activejob (= 7.0.3.1) 128 activemodel (= 7.0.3.1) 129 activerecord (= 7.0.3.1) 130 activestorage (= 7.0.3.1) 131 activesupport (= 7.0.3.1) 132 bundler (>= 1.15.0) 133 railties (= 7.0.3.1) 134 rails-dom-testing (2.0.3) 135 activesupport (>= 4.2.0) 136 nokogiri (>= 1.6) 137 rails-html-sanitizer (1.4.3) 138 loofah (~> 2.3) 139 railties (7.0.3.1) 140 actionpack (= 7.0.3.1) 141 activesupport (= 7.0.3.1) 142 method_source 143 rake (>= 12.2) 144 thor (~> 1.0) 145 zeitwerk (~> 2.5) 146 rake (13.0.6) 147 reline (0.3.1) 148 io-console (~> 0.5) 149 strscan (3.0.3) 150 thor (1.2.1) 151 timeout (0.3.0) 152 tzinfo (2.0.5) 153 concurrent-ruby (~> 1.0) 154 websocket-driver (0.7.5) 155 websocket-extensions (>= 0.1.0) 156 websocket-extensions (0.1.5) 157 zeitwerk (2.6.0) 158 159PLATFORMS 160 x86_64-linux 161 162DEPENDENCIES 163 bootsnap 164 debug 165 mysql2 (~> 0.5) 166 puma (~> 5.0) 167 rails (~> 7.0.3, >= 7.0.3.1) 168 tzinfo-data 169 170RUBY VERSION 171 ruby 3.1.1p18 172 173BUNDLED WITH 174 2.3.7

試したこと

docker-compose run api bundle install を実行後、docker-compose up

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

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

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

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

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

guest

回答1

0

自己解決

docker-compose downでコンテナを停止後、
docker-compose build --no-cacheでコンテナを再作成することで解決しました

投稿2022/07/23 00:09

kaze0000

総合スコア15

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.51%

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

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

質問する

関連した質問