32
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-composeで、rails dbconsoleが使えなくてハマった話。

Posted at

Dockerパネェ

みなさん、こんにちは。欅坂46のてちとりさが推しメンの内田です。
2期生の藤吉ちゃんも最近推してます。

DockerとRailsを使って、webサービスを現在作っているんですが、localにrubyやらmysqlやらを入れなくても開発ができちゃうって、なんて素晴らしいんだろっていつも思ってます。ありがとうありがとうm(_ _)m

でもね?

だけどもだっけっd、、
Dockerを使っているととてつもない壁にぶち当たるときが来るんですよ。
それも何度も。

そんなときはやっぱり気が滅入っちゃって、やっぱりローカル環境にruby入れて開発しようかなぁとか思っちゃうんですよ。
いやぁ、まいったなぁって。

そしてハマった

おハマりしました。

$ docker-compose run web rails dbconsole
Couldn't find database client: mysql, mysql5. Check your $PATH and try again. docker

それまで順調に開発していたので、いざ手が止まってしまったら、疲れがブワッと出てきます。
そんなときはYouTubuで欅坂の動画でも見ましょう。

解決策見つかる

ググりにググってやっと見つけたのが、このサイトでした。
docker-composeでRailsの開発環境を作る
この記事を読んで、ふと気づいたことが、

**あれ、apt-getのところちょっと違うぞ??**ってこと

この方はpostgresql-clientを入れています。
どうやら、mysqlのimageを用意して満足していちゃだめらしいですね。
ごめんなさい:open_hands:

webサーバー側のDockerfileにmysql-clientを入れていないからエラーになっていたんです。
修正したDockerfileはこんな感じ。

FROM ruby:2.6.3
# mysql-clientを入れないと、pathが通らないよって怒られる。
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs mysql-client
RUN mkdir /web
WORKDIR /web
ADD web/Gemfile /web/Gemfile
ADD web/Gemfile.lock /web/Gemfile.lock
RUN bundle install
ADD web /web

そして、もう一度dockerをビルド。

$ docker-compose build

勇気を振り絞って、再挑戦してみましょう。

$ docker-compose run web rails dbconsole

Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [web_development]> 

動いた:innocent:

これで開発進められるぅぅ!
やったぁぁ!

この記事を読んで、あなたもやっぱDocker最高かよ!っていうことを再確認していただけたら嬉しいです! :whale:

おわり。

32
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?