質問編集履歴

3

[ADD] コンテナ内の環境変数の状態

2019/06/09 06:17

投稿

task4233
task4233

スコア106

test CHANGED
File without changes
test CHANGED
@@ -126,6 +126,60 @@
126
126
 
127
127
  # 追記
128
128
 
129
+ ## コンテナ内で確認した環境変数の内容
130
+
131
+ 環境変数は正しく反映されているらしいです...
132
+
133
+ では何故mysql自体に反映されていないのでしょうか...?
134
+
135
+
136
+
137
+ ```bash
138
+
139
+ $ docker ps
140
+
141
+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
142
+
143
+ 02a3b0b8f72d mysql:8.0 "docker-entrypoint.s…" 2 seconds ago Up Less than a second 0.0.0.0:3306->3306/tcp, 33060/tcp mysql_host
144
+
145
+ $ docker exec -it 02a /bin/bash
146
+
147
+ root@02a3b0b8f72d:/# env
148
+
149
+ MYSQL_PASSWORD=docker
150
+
151
+ TZ=Asia/Tokyo
152
+
153
+ HOSTNAME=02a3b0b8f72d
154
+
155
+ MYSQL_DATABASE=sampleDB
156
+
157
+ MYSQL_ROOT_PASSWORD=root
158
+
159
+ PWD=/
160
+
161
+ HOME=/root
162
+
163
+ MYSQL_MAJOR=8.0
164
+
165
+ GOSU_VERSION=1.7
166
+
167
+ MYSQL_USER=docker
168
+
169
+ MYSQL_VERSION=8.0.16-2debian9
170
+
171
+ TERM=xterm
172
+
173
+ SHLVL=1
174
+
175
+ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
176
+
177
+ _=/usr/bin/env
178
+
179
+ ```
180
+
181
+
182
+
129
183
  ## docker-compose logs db で見れるログ
130
184
 
131
185
  以下の通りです。

2

[ADD] sqlやinit用のファイル群

2019/06/09 06:16

投稿

task4233
task4233

スコア106

test CHANGED
File without changes
test CHANGED
@@ -236,6 +236,130 @@
236
236
 
237
237
 
238
238
 
239
+ ## sqlファイルやinit用のファイル群
240
+
241
+ 作成に際して, 以下の記事を参考にしました。
242
+
243
+ - [docker-compose でMySQL環境簡単構築](https://qiita.com/A-Kira/items/f401aea261693c395966)
244
+
245
+
246
+
247
+ フォルダ構成は以下の通りです。
248
+
249
+ ```bash
250
+
251
+ .
252
+
253
+ ├── docker
254
+
255
+ │   └── db
256
+
257
+ │  ├── data
258
+
259
+ │ ├── my.cnf
260
+
261
+ │ └── sql
262
+
263
+ │ ├── create-user-table.sql
264
+
265
+ │ └── init-database.sh
266
+
267
+ ├── docker-compose.yml
268
+
269
+ └── init-mysql.sh
270
+
271
+ ```
272
+
273
+
274
+
275
+ ### ./docker/db/my.cnf
276
+
277
+ ```
278
+
279
+ // ./docker/db/my.cnf
280
+
281
+ [mysqld]
282
+
283
+ character-set-server=utf8mb4
284
+
285
+ collation-server=utf8mb4_unicode_ci
286
+
287
+
288
+
289
+ [client]
290
+
291
+ default-character-set=utf8mb4
292
+
293
+ port = 3306
294
+
295
+ user = docker
296
+
297
+ password = docker
298
+
299
+ ```
300
+
301
+
302
+
303
+ ### ./docker/db/sql/create-user-table.sql
304
+
305
+ ```sql
306
+
307
+ -- User Table
308
+
309
+ drop table if exists `User`;
310
+
311
+
312
+
313
+ create table if not exists `User`
314
+
315
+ (
316
+
317
+ `id` INT(8) AUTO_INCREMENT,
318
+
319
+ `name` VARCHAR(64) NOT NULL,
320
+
321
+ `hashed_pass` VARCHAR(64) NOT NULL,
322
+
323
+ primary key(`id`)
324
+
325
+ ) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
326
+
327
+ ```
328
+
329
+
330
+
331
+ ### ./docker/db/sql/init-database.sh
332
+
333
+ ```sh
334
+
335
+ #!/usr/bin/env bash
336
+
337
+ #sleep 90s
338
+
339
+
340
+
341
+ #run the setup script to create the DB and the schema in the DB
342
+
343
+ mysql --defaults-extra-file=/etc/mysql/my.cnf sampleDB < "/docker-entrypoint-initdb.d/create-user-table.sql"
344
+
345
+ ```
346
+
347
+
348
+
349
+ ### ./init-mysql.sh
350
+
351
+ ```sh
352
+
353
+ #!/bin/sh
354
+
355
+ docker-compose exec db bash -c "chmod 0775 docker-entrypoint-initdb.d/init-database.sh"
356
+
357
+ docker-compose exec db basg -c "./docker-entrypoint-initdb.d/init-database.sh"
358
+
359
+ ```
360
+
361
+
362
+
239
363
  # 実行環境
240
364
 
241
365
  - macOS Mojave version 10.14.1

1

[ADD} docker-compose logs dbの結果

2019/06/09 05:52

投稿

task4233
task4233

スコア106

test CHANGED
File without changes
test CHANGED
@@ -124,6 +124,118 @@
124
124
 
125
125
 
126
126
 
127
+ # 追記
128
+
129
+ ## docker-compose logs db で見れるログ
130
+
131
+ 以下の通りです。
132
+
133
+
134
+
135
+ 私としては, まず4行目の`[Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.`が問題だと考えています。
136
+
137
+ なぜなら, `docker-compose.yml`で設定したはずだからです。
138
+
139
+ 何故なのか...
140
+
141
+
142
+
143
+ ```text
144
+
145
+ Attaching to mysql_host
146
+
147
+ mysql_host | Initializing database
148
+
149
+ mysql_host | 2019-06-09T05:25:15.104523Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
150
+
151
+ mysql_host | 2019-06-09T05:25:15.106187Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server in progress as process 28
152
+
153
+ mysql_host | 2019-06-09T05:25:24.300438Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
154
+
155
+ mysql_host | 2019-06-09T05:25:30.689081Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.16) initializing of server has completed
156
+
157
+ mysql_host | Database initialized
158
+
159
+ mysql_host | MySQL init process in progress...
160
+
161
+ mysql_host | MySQL init process in progress...
162
+
163
+ mysql_host | MySQL init process in progress...
164
+
165
+ mysql_host | 2019-06-09T05:25:33.999456Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
166
+
167
+ mysql_host | 2019-06-09T05:25:34.006555Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 79
168
+
169
+ mysql_host | 2019-06-09T05:25:36.482160Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
170
+
171
+ mysql_host | 2019-06-09T05:25:36.509381Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
172
+
173
+ mysql_host | 2019-06-09T05:25:36.581626Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.16' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
174
+
175
+ mysql_host | 2019-06-09T05:25:36.843695Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
176
+
177
+ mysql_host | MySQL init process in progress...
178
+
179
+ mysql_host | MySQL init process in progress...
180
+
181
+ mysql_host | MySQL init process in progress...
182
+
183
+ mysql_host | MySQL init process in progress...
184
+
185
+ mysql_host | MySQL init process in progress...
186
+
187
+ mysql_host | MySQL init process in progress...
188
+
189
+ mysql_host | MySQL init process in progress...
190
+
191
+ mysql_host | MySQL init process in progress...
192
+
193
+ mysql_host | MySQL init process in progress...
194
+
195
+ mysql_host | MySQL init process in progress...
196
+
197
+ mysql_host | MySQL init process in progress...
198
+
199
+ mysql_host | MySQL init process in progress...
200
+
201
+ mysql_host | MySQL init process in progress...
202
+
203
+ mysql_host | MySQL init process in progress...
204
+
205
+ mysql_host | MySQL init process in progress...
206
+
207
+ mysql_host | MySQL init process in progress...
208
+
209
+ mysql_host | MySQL init process in progress...
210
+
211
+ mysql_host | MySQL init process in progress...
212
+
213
+ mysql_host | MySQL init process in progress...
214
+
215
+ mysql_host | MySQL init process in progress...
216
+
217
+ mysql_host | MySQL init process in progress...
218
+
219
+ mysql_host | MySQL init process in progress...
220
+
221
+ mysql_host | MySQL init process in progress...
222
+
223
+ mysql_host | MySQL init process in progress...
224
+
225
+ mysql_host | MySQL init process in progress...
226
+
227
+ mysql_host | MySQL init process in progress...
228
+
229
+ mysql_host | MySQL init process in progress...
230
+
231
+ mysql_host | MySQL init process in progress...
232
+
233
+ mysql_host | MySQL init process failed.
234
+
235
+ ```
236
+
237
+
238
+
127
239
  # 実行環境
128
240
 
129
241
  - macOS Mojave version 10.14.1