質問編集履歴
3
[ADD] コンテナ内の環境変数の状態
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用のファイル群
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の結果
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
|
+
[36mmysql_host |[0m Initializing database
|
148
|
+
|
149
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m Database initialized
|
158
|
+
|
159
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
160
|
+
|
161
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
162
|
+
|
163
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
164
|
+
|
165
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m 2019-06-09T05:25:34.006555Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 79
|
168
|
+
|
169
|
+
[36mmysql_host |[0m 2019-06-09T05:25:36.482160Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
|
170
|
+
|
171
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m 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
|
+
[36mmysql_host |[0m 2019-06-09T05:25:36.843695Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock'
|
176
|
+
|
177
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
178
|
+
|
179
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
180
|
+
|
181
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
182
|
+
|
183
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
184
|
+
|
185
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
186
|
+
|
187
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
188
|
+
|
189
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
190
|
+
|
191
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
192
|
+
|
193
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
194
|
+
|
195
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
196
|
+
|
197
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
198
|
+
|
199
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
200
|
+
|
201
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
202
|
+
|
203
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
204
|
+
|
205
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
206
|
+
|
207
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
208
|
+
|
209
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
210
|
+
|
211
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
212
|
+
|
213
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
214
|
+
|
215
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
216
|
+
|
217
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
218
|
+
|
219
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
220
|
+
|
221
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
222
|
+
|
223
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
224
|
+
|
225
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
226
|
+
|
227
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
228
|
+
|
229
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
230
|
+
|
231
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
232
|
+
|
233
|
+
[36mmysql_host |[0m MySQL init process failed.
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
|
238
|
+
|
127
239
|
# 実行環境
|
128
240
|
|
129
241
|
- macOS Mojave version 10.14.1
|