質問編集履歴

4

タイトル、$ docker-compose psの結果

2019/10/08 12:19

投稿

raintree
raintree

スコア10

test CHANGED
@@ -1 +1 @@
1
- Mysql2::Error::ConnectionErrorが表示される
1
+ Unknown MySQL server host 'db' (0)を消したい
test CHANGED
@@ -56,99 +56,15 @@
56
56
 
57
57
 
58
58
 
59
+ $ docker-compose ps
60
+
61
+ Name Command State Ports
62
+
59
- vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `connect'
63
+ --------------------------------------------------------------------------------
60
-
61
- vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize'
64
+
62
-
63
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new'
64
-
65
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
66
-
67
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
68
-
69
- 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'
70
-
71
- 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'
72
-
73
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
74
-
75
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
76
-
77
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
78
-
79
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1010:in `retrieve_connection'
80
-
81
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
82
-
83
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:90:in `connection'
84
-
85
- vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.2/lib/active_record/migration.rb:554:in `call'
86
-
87
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
88
-
89
- vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:98:in `run_callbacks'
90
-
91
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
92
-
93
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
94
-
95
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
96
-
97
- vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:135:in `call_app'
98
-
99
- vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:30:in `block in call'
100
-
101
- vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
102
-
103
- vendor/bundle/ruby/2.6.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
104
-
105
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
106
-
107
- vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:38:in `call_app'
108
-
109
- vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in `block in call'
110
-
111
- vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in `block in tagged'
112
-
113
- vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:28:in `tagged'
114
-
115
- vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in `tagged'
116
-
117
- vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in `call'
118
-
119
- vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
120
-
121
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
122
-
123
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/request_id.rb:27:in `call'
124
-
125
- vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'
126
-
127
- vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/runtime.rb:22:in `call'
65
+ rails_test_db_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp
128
-
129
- vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
66
+
130
-
131
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in `call'
132
-
133
- vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2/lib/action_dispatch/middleware/static.rb:127:in `call'
134
-
135
- vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in `call'
136
-
137
- vendor/bundle/ruby/2.6.0/gems/webpacker-4.0.7/lib/webpacker/dev_server_proxy.rb:29:in `perform_request'
138
-
139
- vendor/bundle/ruby/2.6.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
140
-
141
- vendor/bundle/ruby/2.6.0/gems/railties-5.2.2/lib/rails/engine.rb:524:in `call'
67
+ rails_test_web_1 bundle exec rails s -p 300 ... Exit 1
142
-
143
- vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/configuration.rb:227:in `call'
144
-
145
- vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:660:in `handle_request'
146
-
147
- vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:474:in `process_client'
148
-
149
- vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:334:in `block in run'
150
-
151
- vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
152
68
 
153
69
  ```
154
70
 

3

ファイルを更新しました

2019/10/08 12:19

投稿

raintree
raintree

スコア10

test CHANGED
File without changes
test CHANGED
@@ -182,7 +182,7 @@
182
182
 
183
183
  stdin_open: true
184
184
 
185
- db: # Railsのhostと一致させる
185
+ db:
186
186
 
187
187
  image: mysql:5.7
188
188
 
@@ -192,13 +192,7 @@
192
192
 
193
193
  environment:
194
194
 
195
- MYSQL_USER: 'webapp'
196
-
197
- MYSQL_PASSWORD: 'webapp_pass'
198
-
199
- MYSQL_DATABASE: 'rails_app_development'
200
-
201
- MYSQL_ROOT_PASSWORD: 'pass'
195
+ MYSQL_ROOT_PASSWORD: password
202
196
 
203
197
  volumes:
204
198
 
@@ -238,11 +232,11 @@
238
232
 
239
233
  encoding: utf8
240
234
 
241
- pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
235
+ pool: 5
242
-
236
+
243
- username: webapp
237
+ username: root
244
-
238
+
245
- password: webapp_pass
239
+ password: password
246
240
 
247
241
  host: db
248
242
 

2

環境について追記しました

2019/10/07 13:18

投稿

raintree
raintree

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,13 @@
1
+ #環境
2
+
3
+ MacOS Mojave 10.14.6
4
+
5
+ Ruby 2.6.4
6
+
7
+ Rails 5.2.2
8
+
9
+ mysql Ver 8.0.17 for osx10.14 on x86_64 (Homebrew)
10
+
1
11
  #1.実現したいこと
2
12
 
3
13
  rails sでサーバーを立ち上げたい

1

ファイルを2つ追加しました

2019/10/07 08:09

投稿

raintree
raintree

スコア10

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Unknown MySQL server host 'db' (0)
10
10
 
11
- #3.ターミナル
11
+ #3.terminal
12
12
 
13
13
  ```terminal
14
14
 
@@ -141,3 +141,171 @@
141
141
  vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
142
142
 
143
143
  ```
144
+
145
+ #4.docker-compose.yml
146
+
147
+ ```ここに言語を入力
148
+
149
+ version: '3'
150
+
151
+ services:
152
+
153
+ web:
154
+
155
+ build: .
156
+
157
+ command: bundle exec rails s -p 3000 -b '0.0.0.0'
158
+
159
+ volumes:
160
+
161
+ - .:/app
162
+
163
+ ports:
164
+
165
+ - 3000:3000
166
+
167
+ depends_on:
168
+
169
+ - db
170
+
171
+ tty: true
172
+
173
+ stdin_open: true
174
+
175
+ db: # Railsのhostと一致させる
176
+
177
+ image: mysql:5.7
178
+
179
+ volumes:
180
+
181
+ - db-volume:/var/lib/mysql
182
+
183
+ environment:
184
+
185
+ MYSQL_USER: 'webapp'
186
+
187
+ MYSQL_PASSWORD: 'webapp_pass'
188
+
189
+ MYSQL_DATABASE: 'rails_app_development'
190
+
191
+ MYSQL_ROOT_PASSWORD: 'pass'
192
+
193
+ volumes:
194
+
195
+ db-volume:
196
+
197
+ ```
198
+
199
+ #5.database.yml
200
+
201
+ ```ここに言語を入力
202
+
203
+ # MySQL. Versions 5.0 and up are supported.
204
+
205
+ #
206
+
207
+ # Install the MySQL driver
208
+
209
+ # gem install mysql2
210
+
211
+ #
212
+
213
+ # Ensure the MySQL gem is defined in your Gemfile
214
+
215
+ # gem 'mysql2'
216
+
217
+ #
218
+
219
+ # And be sure to use new-style password hashing:
220
+
221
+ # http://dev.mysql.com/doc/refman/5.7/en/old-client.html
222
+
223
+ #
224
+
225
+ default: &default
226
+
227
+ adapter: mysql2
228
+
229
+ encoding: utf8
230
+
231
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
232
+
233
+ username: webapp
234
+
235
+ password: webapp_pass
236
+
237
+ host: db
238
+
239
+
240
+
241
+ development:
242
+
243
+ <<: *default
244
+
245
+ database: app_development
246
+
247
+
248
+
249
+ # Warning: The database defined as "test" will be erased and
250
+
251
+ # re-generated from your development database when you run "rake".
252
+
253
+ # Do not set this db to the same as development or production.
254
+
255
+ test:
256
+
257
+ <<: *default
258
+
259
+ database: app_test
260
+
261
+
262
+
263
+ # As with config/secrets.yml, you never want to store sensitive information,
264
+
265
+ # like your database password, in your source code. If your source code is
266
+
267
+ # ever seen by anyone, they now have access to your database.
268
+
269
+ #
270
+
271
+ # Instead, provide the password as a unix environment variable when you boot
272
+
273
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
274
+
275
+ # for a full rundown on how to provide these environment variables in a
276
+
277
+ # production deployment.
278
+
279
+ #
280
+
281
+ # On Heroku and other platform providers, you may have a full connection URL
282
+
283
+ # available as an environment variable. For example:
284
+
285
+ #
286
+
287
+ # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
288
+
289
+ #
290
+
291
+ # You can use this database configuration with:
292
+
293
+ #
294
+
295
+ # production:
296
+
297
+ # url: <%= ENV['DATABASE_URL'] %>
298
+
299
+ #
300
+
301
+ production:
302
+
303
+ <<: *default
304
+
305
+ database: app_production
306
+
307
+ username: app
308
+
309
+ password: <%= ENV['APP_DATABASE_PASSWORD'] %>
310
+
311
+ ```