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

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

新規登録して質問してみよう
ただいま回答率
85.46%
MySQL

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

Ruby on Rails

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

Docker

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

Q&A

解決済

1回答

984閲覧

docker-compose run web bundle exec rake db:createをするとmysql2 のgemがないと言われてしまう

otyaotya

総合スコア1

MySQL

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

Ruby on Rails

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

Docker

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

0グッド

0クリップ

投稿2021/07/16 23:15

編集2021/07/17 01:23

既存アプリにdockerを導入したく以下記事を参考に進めています。
Ruby on Rails 「途中まで作ったアプリにDockerを導入したい」に挑戦してみる(MySQL / Sequel Pro)

docker-compose run web bundle exec rake db:createをすると

mysql2-0.5.3が見つからないとエラーになる問題で困っています。
原因または解決策をご存知の方はいらっしゃいませんか。

私の行った手順は以下です。
(1)bundle install
→結果

$ bundle install Using rake 13.0.6 Using concurrent-ruby 1.1.9 Using i18n 1.8.10 Using minitest 5.14.4 Using thread_safe 0.3.6 Using tzinfo 1.2.9 Using activesupport 5.2.6 Using builder 3.2.4 Using erubi 1.10.0 Using mini_portile2 2.5.3 Using racc 1.5.2 Using nokogiri 1.11.7 (x86_64-darwin) Using rails-dom-testing 2.0.3 Using crass 1.0.6 Using loofah 2.10.0 Using rails-html-sanitizer 1.3.0 Using actionview 5.2.6 Using rack 2.2.3 Using rack-test 1.1.0 Using actionpack 5.2.6 Using nio4r 2.5.7 Using websocket-extensions 0.1.5 Using websocket-driver 0.7.5 Using actioncable 5.2.6 Using globalid 0.4.2 Using activejob 5.2.6 Using mini_mime 1.1.0 Using mail 2.7.1 Using actionmailer 5.2.6 Using activemodel 5.2.6 Using arel 9.0.0 Using activerecord 5.2.6 Using marcel 1.0.1 Using activestorage 5.2.6 Using public_suffix 4.0.6 Using addressable 2.8.0 Using amazing_print 1.3.0 Using anbt-sql-formatter 0.1.0 Using execjs 2.8.1 Using autoprefixer-rails 10.2.5.1 Using bcrypt 3.1.16 Using bindex 0.8.1 Using msgpack 1.4.2 Using bootsnap 1.7.5 Using rb-fsevent 0.11.0 Using ffi 1.15.3 Using rb-inotify 0.10.1 Using sass-listen 4.0.0 Using sass 3.7.4 Using bootstrap-sass 3.3.7 Using bundler 1.17.2 Using byebug 11.1.3 Using regexp_parser 2.1.1 Using xpath 3.2.0 Using capybara 3.35.3 Using childprocess 3.0.0 Using coderay 1.1.3 Using coffee-script-source 1.12.2 Using coffee-script 2.4.1 Using method_source 1.0.0 Using thor 1.1.0 Using railties 5.2.6 Using coffee-rails 4.2.2 Using orm_adapter 0.5.0 Using responders 3.0.1 Using warden 1.2.9 Using devise 4.8.0 Using jbuilder 2.11.2 Using jquery-rails 4.4.0 Using jquery-ui-rails 6.0.1 Using ruby_dep 1.5.0 Using listen 3.1.5 Using mysql2 0.5.3 Using pry 0.14.1 Using pry-rails 0.3.9 Using puma 3.12.6 Using rack-proxy 0.7.0 Using sprockets 3.7.2 Using sprockets-rails 3.2.2 Using rails 5.2.6 Using rails-flog 1.6.1 Using rubyzip 2.3.2 Using sassc 2.4.0 Using tilt 2.0.10 Using sassc-rails 2.1.2 Using sass-rails 6.0.0 Using selenium-webdriver 3.142.7 Using spring 2.1.1 Using spring-watcher-listen 2.0.1 Using turbolinks-source 5.2.0 Using turbolinks 5.2.1 Using tzinfo-data 1.2021.1 Using uglifier 4.2.0 Using web-console 3.7.0 Using webdrivers 4.6.0 Using webpacker 4.3.0 Bundle complete! 25 Gemfile dependencies, 96 gems now installed. Bundled gems are installed into `./vendor/bundle`

(2)mysql2 のgemがない?トラブルシューティング記事を参考に実行

$bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include" $bundle install --path=vendor/bundle

→結果
(1)と同じ結果

(3)以下を実行

gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib

→結果

Fetching mysql2-0.5.2.gem Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib' This could take a while... Successfully installed mysql2-0.5.2 Parsing documentation for mysql2-0.5.2 Installing ri documentation for mysql2-0.5.2 Done installing documentation for mysql2 after 0 seconds 1 gem installed

Dockerfile

1FROM ruby:2.6.6 2RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* 3RUN apt-get update && apt-get install -y default-mysql-client --no-install-recommends && rm -rf /var/lib/apt/lists/* 4RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs 5RUN mkdir /workdir 6WORKDIR /workdir 7ADD Gemfile /workdir/Gemfile 8ADD Gemfile.lock /workdir/Gemfile.lock 9RUN bundle install 10ADD . /workdir

docker

1version: '3' 2services: 3 db: 4 image: mysql:5.7 5 environment: 6 MYSQL_DATABASE: docker_development 7 MYSQL_ROOT_PASSWORD: 'password' 8 MYSQL_USER: hoge 9 MYSQL_PASSWORD: 'password' 10 ports: 11 - "4306:3306" 12 web: 13 build: 14 context: . 15 dockerfile: Dockerfile 16 command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0' 17 tty: true 18 stdin_open: true 19 depends_on: 20 - db 21 ports: 22 - "3000:3000" 23 volumes: 24 - .:/workdir

database.yml

1 2default: &default 3 adapter: mysql2 4 encoding: utf8 5 pool: 5 6 host: db 7 8development: 9 <<: *default 10 username: hoge 11 password: password 12 database: docker_development 13 14production: 15 <<: *default 16 database: docker_production 17 username: docker 18 password: <%= ENV['DOCKER_DATABASE_PASSWORD'] %>

なお、私の環境は以下の通りです。
macOS Catalina バージョン 10.15.6
Ruby 2.6.6
Rails 5.2.6
mysql 8.0.25

宜しくお願いいたします。

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

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

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

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

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

guest

回答1

0

自己解決

投稿2021/07/20 06:38

otyaotya

総合スコア1

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問