質問編集履歴
4
タイトル、$ docker-compose psの結果
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Unknown MySQL server host 'db' (0)を消したい
|
body
CHANGED
@@ -27,53 +27,11 @@
|
|
27
27
|
|
28
28
|
Mysql2::Error::ConnectionError (Unknown MySQL server host 'db' (0)):
|
29
29
|
|
30
|
+
$ docker-compose ps
|
31
|
+
Name Command State Ports
|
30
|
-
|
32
|
+
--------------------------------------------------------------------------------
|
31
|
-
vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize'
|
32
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new'
|
33
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
|
34
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
|
35
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
|
36
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
|
37
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
|
38
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
|
39
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
|
40
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1010:in `retrieve_connection'
|
41
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
|
42
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:90:in `connection'
|
43
|
-
vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/migration.rb:554:in `call'
|
44
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
|
45
|
-
vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:98:in `run_callbacks'
|
46
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
|
47
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
|
48
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
|
49
|
-
vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:135:in `call_app'
|
50
|
-
vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:30:in `block in call'
|
51
|
-
vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
|
52
|
-
vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
|
53
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
|
54
|
-
vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:38:in `call_app'
|
55
|
-
vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in `block in call'
|
56
|
-
vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in `block in tagged'
|
57
|
-
vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:28:in `tagged'
|
58
|
-
vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in `tagged'
|
59
|
-
vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in `call'
|
60
|
-
vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
|
61
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
|
62
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/request_id.rb:27:in `call'
|
63
|
-
vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'
|
64
|
-
|
33
|
+
rails_test_db_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp
|
65
|
-
vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
|
66
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
|
67
|
-
vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/static.rb:127:in `call'
|
68
|
-
vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in `call'
|
69
|
-
vendor/bundle/ruby/2.6.0/gems/webpacker-4.0.7/lib/webpacker/dev_server_proxy.rb:29:in `perform_request'
|
70
|
-
vendor/bundle/ruby/2.6.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
|
71
|
-
|
34
|
+
rails_test_web_1 bundle exec rails s -p 300 ... Exit 1
|
72
|
-
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/configuration.rb:227:in `call'
|
73
|
-
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:660:in `handle_request'
|
74
|
-
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:474:in `process_client'
|
75
|
-
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:334:in `block in run'
|
76
|
-
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
|
77
35
|
```
|
78
36
|
#4.docker-compose.yml
|
79
37
|
```ここに言語を入力
|
3
ファイルを更新しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -90,15 +90,12 @@
|
|
90
90
|
- db
|
91
91
|
tty: true
|
92
92
|
stdin_open: true
|
93
|
-
db:
|
93
|
+
db:
|
94
94
|
image: mysql:5.7
|
95
95
|
volumes:
|
96
96
|
- db-volume:/var/lib/mysql
|
97
97
|
environment:
|
98
|
-
MYSQL_USER: 'webapp'
|
99
|
-
MYSQL_PASSWORD: 'webapp_pass'
|
100
|
-
MYSQL_DATABASE: 'rails_app_development'
|
101
|
-
MYSQL_ROOT_PASSWORD:
|
98
|
+
MYSQL_ROOT_PASSWORD: password
|
102
99
|
volumes:
|
103
100
|
db-volume:
|
104
101
|
```
|
@@ -118,9 +115,9 @@
|
|
118
115
|
default: &default
|
119
116
|
adapter: mysql2
|
120
117
|
encoding: utf8
|
121
|
-
pool:
|
118
|
+
pool: 5
|
122
|
-
username:
|
119
|
+
username: root
|
123
|
-
password:
|
120
|
+
password: password
|
124
121
|
host: db
|
125
122
|
|
126
123
|
development:
|
2
環境について追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
#環境
|
2
|
+
MacOS Mojave 10.14.6
|
3
|
+
Ruby 2.6.4
|
4
|
+
Rails 5.2.2
|
5
|
+
mysql Ver 8.0.17 for osx10.14 on x86_64 (Homebrew)
|
1
6
|
#1.実現したいこと
|
2
7
|
rails sでサーバーを立ち上げたい
|
3
8
|
#2.問題
|
1
ファイルを2つ追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#2.問題
|
4
4
|
Mysql2::Error::ConnectionError
|
5
5
|
Unknown MySQL server host 'db' (0)
|
6
|
-
#3.
|
6
|
+
#3.terminal
|
7
7
|
```terminal
|
8
8
|
$ rails server
|
9
9
|
=> Booting Puma
|
@@ -69,4 +69,88 @@
|
|
69
69
|
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:474:in `process_client'
|
70
70
|
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:334:in `block in run'
|
71
71
|
vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
|
72
|
+
```
|
73
|
+
#4.docker-compose.yml
|
74
|
+
```ここに言語を入力
|
75
|
+
version: '3'
|
76
|
+
services:
|
77
|
+
web:
|
78
|
+
build: .
|
79
|
+
command: bundle exec rails s -p 3000 -b '0.0.0.0'
|
80
|
+
volumes:
|
81
|
+
- .:/app
|
82
|
+
ports:
|
83
|
+
- 3000:3000
|
84
|
+
depends_on:
|
85
|
+
- db
|
86
|
+
tty: true
|
87
|
+
stdin_open: true
|
88
|
+
db: # Railsのhostと一致させる
|
89
|
+
image: mysql:5.7
|
90
|
+
volumes:
|
91
|
+
- db-volume:/var/lib/mysql
|
92
|
+
environment:
|
93
|
+
MYSQL_USER: 'webapp'
|
94
|
+
MYSQL_PASSWORD: 'webapp_pass'
|
95
|
+
MYSQL_DATABASE: 'rails_app_development'
|
96
|
+
MYSQL_ROOT_PASSWORD: 'pass'
|
97
|
+
volumes:
|
98
|
+
db-volume:
|
99
|
+
```
|
100
|
+
#5.database.yml
|
101
|
+
```ここに言語を入力
|
102
|
+
# MySQL. Versions 5.0 and up are supported.
|
103
|
+
#
|
104
|
+
# Install the MySQL driver
|
105
|
+
# gem install mysql2
|
106
|
+
#
|
107
|
+
# Ensure the MySQL gem is defined in your Gemfile
|
108
|
+
# gem 'mysql2'
|
109
|
+
#
|
110
|
+
# And be sure to use new-style password hashing:
|
111
|
+
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
|
112
|
+
#
|
113
|
+
default: &default
|
114
|
+
adapter: mysql2
|
115
|
+
encoding: utf8
|
116
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
117
|
+
username: webapp
|
118
|
+
password: webapp_pass
|
119
|
+
host: db
|
120
|
+
|
121
|
+
development:
|
122
|
+
<<: *default
|
123
|
+
database: app_development
|
124
|
+
|
125
|
+
# Warning: The database defined as "test" will be erased and
|
126
|
+
# re-generated from your development database when you run "rake".
|
127
|
+
# Do not set this db to the same as development or production.
|
128
|
+
test:
|
129
|
+
<<: *default
|
130
|
+
database: app_test
|
131
|
+
|
132
|
+
# As with config/secrets.yml, you never want to store sensitive information,
|
133
|
+
# like your database password, in your source code. If your source code is
|
134
|
+
# ever seen by anyone, they now have access to your database.
|
135
|
+
#
|
136
|
+
# Instead, provide the password as a unix environment variable when you boot
|
137
|
+
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
138
|
+
# for a full rundown on how to provide these environment variables in a
|
139
|
+
# production deployment.
|
140
|
+
#
|
141
|
+
# On Heroku and other platform providers, you may have a full connection URL
|
142
|
+
# available as an environment variable. For example:
|
143
|
+
#
|
144
|
+
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
|
145
|
+
#
|
146
|
+
# You can use this database configuration with:
|
147
|
+
#
|
148
|
+
# production:
|
149
|
+
# url: <%= ENV['DATABASE_URL'] %>
|
150
|
+
#
|
151
|
+
production:
|
152
|
+
<<: *default
|
153
|
+
database: app_production
|
154
|
+
username: app
|
155
|
+
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
|
72
156
|
```
|