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

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

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

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

Ruby on Rails 6

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

Docker

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

Q&A

1回答

536閲覧

docker-composeでrailsを立ち上げたい

hase744

総合スコア57

docker-compose

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

Ruby on Rails 6

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

Docker

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

0グッド

0クリップ

投稿2022/02/23 20:48

編集2022/02/24 21:22

docker-composeでdbの作成が以下のエラーによってできません
ググって色々試しましたがうまくいきませんでした
現在ローカルではsqlite3を使用しているのですが公式ドキュメントyoutubeなどではmysqlやpostgresqlを使用されています。
dockerで作成する場合、コンテナ内の設定とローカルの設定を同じにする必要はありますか?
ちなみにdocker内のアプリを起動させることはできます

command

1ser@Users-MBP-70 official_document2 % docker-compose run web rake db:create 2Creating official_document2_web_run ... done 3could not connect to server: No such file or directory 4 Is the server running locally and accepting 5 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 6Couldn't create 'myapp_development' database. Please check your configuration. 7rake aborted! 8ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory 9 Is the server running locally and accepting 10 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 11/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client' 12/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client' 13/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection' 14/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send' 15/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection' 16/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection' 17/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection' 18/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection' 19/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout' 20/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection' 21/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection' 22/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:327:in `retrieve_connection' 23/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:283:in `connection' 24/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection' 25/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create' 26/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:133:in `create' 27/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current' 28/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration' 29/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `each' 30/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration' 31/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each' 32/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration' 33/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `create_current' 34/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>' 35/usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>' 36 37Caused by: 38PG::ConnectionBad: could not connect to server: No such file or directory 39 Is the server running locally and accepting 40 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? 41/usr/local/bundle/gems/pg-1.3.3/lib/pg/connection.rb:701:in `connect_start' 42/usr/local/bundle/gems/pg-1.3.3/lib/pg/connection.rb:701:in `new' 43/usr/local/bundle/gems/pg-1.3.3/lib/pg.rb:69:in `connect' 44/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client' 45/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection' 46/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send' 47/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection' 48/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection' 49/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection' 50/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection' 51/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout' 52/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection' 53/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection' 54/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:327:in `retrieve_connection' 55/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/connection_handling.rb:283:in `connection' 56/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection' 57/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create' 58/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:133:in `create' 59/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `block in create_current' 60/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:506:in `block (2 levels) in each_current_configuration' 61/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `each' 62/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:503:in `block in each_current_configuration' 63/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each' 64/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:502:in `each_current_configuration' 65/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/tasks/database_tasks.rb:193:in `create_current' 66/usr/local/bundle/gems/activerecord-6.1.4.6/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>' 67/usr/local/bundle/gems/rake-13.0.6/exe/rake:27:in `<top (required)>' 68Tasks: TOP => db:create 69(See full trace by running task with --trace) 70ERROR: 1

docker

1version: '3' 2services: 3 db: 4 image: mysql:8.0 5 command: --default-authentication-plugin=mysql_native_password 6 volumes: 7 - ./src/db/mysql_data:/var/lib/mysql 8 environment: 9 MYSQL_ROOT_PASSWORD: password 10 web: 11 build: . 12 command: bundle exec rails s -p 3000 -b '0.0.0.0' 13 volumes: 14 - ./src:/app 15 ports: 16 - "3000:3000" 17 depends_on: 18 - db

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2022/02/24 04:43

実際に動かしたdocker-compose.ymlはどのような内容でしょうか
hase744

2022/02/24 21:23

回答ありがとうございます。 追加いたしました
guest

回答1

0

mysql側のポート設定がないですね。

mysqlの方に

ports:
- "3306:3306"

を足してみてください

投稿2022/02/25 01:22

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

hase744

2022/02/25 11:56

ローカル環境のmysqlですか、それともdocker環境内のmysqlですか?
退会済みユーザー

退会済みユーザー

2022/02/25 20:23

回答に書いたのはdocker-composeの話でしたが、ローカル環境にもmysqlが立っているとなるとかぶらないように設定しないといけなさそうです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問