質問編集履歴
3
[ADD] コンテナ内の環境変数の状態
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,6 +62,33 @@
|
|
62
62
|
なにとぞ, よろしくお願いします。
|
63
63
|
|
64
64
|
# 追記
|
65
|
+
## コンテナ内で確認した環境変数の内容
|
66
|
+
環境変数は正しく反映されているらしいです...
|
67
|
+
では何故mysql自体に反映されていないのでしょうか...?
|
68
|
+
|
69
|
+
```bash
|
70
|
+
$ docker ps
|
71
|
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
72
|
+
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
|
73
|
+
$ docker exec -it 02a /bin/bash
|
74
|
+
root@02a3b0b8f72d:/# env
|
75
|
+
MYSQL_PASSWORD=docker
|
76
|
+
TZ=Asia/Tokyo
|
77
|
+
HOSTNAME=02a3b0b8f72d
|
78
|
+
MYSQL_DATABASE=sampleDB
|
79
|
+
MYSQL_ROOT_PASSWORD=root
|
80
|
+
PWD=/
|
81
|
+
HOME=/root
|
82
|
+
MYSQL_MAJOR=8.0
|
83
|
+
GOSU_VERSION=1.7
|
84
|
+
MYSQL_USER=docker
|
85
|
+
MYSQL_VERSION=8.0.16-2debian9
|
86
|
+
TERM=xterm
|
87
|
+
SHLVL=1
|
88
|
+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
89
|
+
_=/usr/bin/env
|
90
|
+
```
|
91
|
+
|
65
92
|
## docker-compose logs db で見れるログ
|
66
93
|
以下の通りです。
|
67
94
|
|
2
[ADD] sqlやinit用のファイル群
title
CHANGED
File without changes
|
body
CHANGED
@@ -117,6 +117,68 @@
|
|
117
117
|
[36mmysql_host |[0m MySQL init process failed.
|
118
118
|
```
|
119
119
|
|
120
|
+
## sqlファイルやinit用のファイル群
|
121
|
+
作成に際して, 以下の記事を参考にしました。
|
122
|
+
- [docker-compose でMySQL環境簡単構築](https://qiita.com/A-Kira/items/f401aea261693c395966)
|
123
|
+
|
124
|
+
フォルダ構成は以下の通りです。
|
125
|
+
```bash
|
126
|
+
.
|
127
|
+
├── docker
|
128
|
+
│ └── db
|
129
|
+
│ ├── data
|
130
|
+
│ ├── my.cnf
|
131
|
+
│ └── sql
|
132
|
+
│ ├── create-user-table.sql
|
133
|
+
│ └── init-database.sh
|
134
|
+
├── docker-compose.yml
|
135
|
+
└── init-mysql.sh
|
136
|
+
```
|
137
|
+
|
138
|
+
### ./docker/db/my.cnf
|
139
|
+
```
|
140
|
+
// ./docker/db/my.cnf
|
141
|
+
[mysqld]
|
142
|
+
character-set-server=utf8mb4
|
143
|
+
collation-server=utf8mb4_unicode_ci
|
144
|
+
|
145
|
+
[client]
|
146
|
+
default-character-set=utf8mb4
|
147
|
+
port = 3306
|
148
|
+
user = docker
|
149
|
+
password = docker
|
150
|
+
```
|
151
|
+
|
152
|
+
### ./docker/db/sql/create-user-table.sql
|
153
|
+
```sql
|
154
|
+
-- User Table
|
155
|
+
drop table if exists `User`;
|
156
|
+
|
157
|
+
create table if not exists `User`
|
158
|
+
(
|
159
|
+
`id` INT(8) AUTO_INCREMENT,
|
160
|
+
`name` VARCHAR(64) NOT NULL,
|
161
|
+
`hashed_pass` VARCHAR(64) NOT NULL,
|
162
|
+
primary key(`id`)
|
163
|
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
164
|
+
```
|
165
|
+
|
166
|
+
### ./docker/db/sql/init-database.sh
|
167
|
+
```sh
|
168
|
+
#!/usr/bin/env bash
|
169
|
+
#sleep 90s
|
170
|
+
|
171
|
+
#run the setup script to create the DB and the schema in the DB
|
172
|
+
mysql --defaults-extra-file=/etc/mysql/my.cnf sampleDB < "/docker-entrypoint-initdb.d/create-user-table.sql"
|
173
|
+
```
|
174
|
+
|
175
|
+
### ./init-mysql.sh
|
176
|
+
```sh
|
177
|
+
#!/bin/sh
|
178
|
+
docker-compose exec db bash -c "chmod 0775 docker-entrypoint-initdb.d/init-database.sh"
|
179
|
+
docker-compose exec db basg -c "./docker-entrypoint-initdb.d/init-database.sh"
|
180
|
+
```
|
181
|
+
|
120
182
|
# 実行環境
|
121
183
|
- macOS Mojave version 10.14.1
|
122
184
|
- docker-compose version 1.23.2, build 1110ad01
|
1
[ADD} docker-compose logs dbの結果
title
CHANGED
File without changes
|
body
CHANGED
@@ -61,6 +61,62 @@
|
|
61
61
|
また, 他に情報が欲しい場合は, コメントしていただければ追記いたします。
|
62
62
|
なにとぞ, よろしくお願いします。
|
63
63
|
|
64
|
+
# 追記
|
65
|
+
## docker-compose logs db で見れるログ
|
66
|
+
以下の通りです。
|
67
|
+
|
68
|
+
私としては, まず4行目の`[Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.`が問題だと考えています。
|
69
|
+
なぜなら, `docker-compose.yml`で設定したはずだからです。
|
70
|
+
何故なのか...
|
71
|
+
|
72
|
+
```text
|
73
|
+
Attaching to mysql_host
|
74
|
+
[36mmysql_host |[0m Initializing database
|
75
|
+
[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.
|
76
|
+
[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
|
77
|
+
[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.
|
78
|
+
[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
|
79
|
+
[36mmysql_host |[0m Database initialized
|
80
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
81
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
82
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
83
|
+
[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.
|
84
|
+
[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
|
85
|
+
[36mmysql_host |[0m 2019-06-09T05:25:36.482160Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
|
86
|
+
[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.
|
87
|
+
[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.
|
88
|
+
[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'
|
89
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
90
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
91
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
92
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
93
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
94
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
95
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
96
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
97
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
98
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
99
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
100
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
101
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
102
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
103
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
104
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
105
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
106
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
107
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
108
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
109
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
110
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
111
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
112
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
113
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
114
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
115
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
116
|
+
[36mmysql_host |[0m MySQL init process in progress...
|
117
|
+
[36mmysql_host |[0m MySQL init process failed.
|
118
|
+
```
|
119
|
+
|
64
120
|
# 実行環境
|
65
121
|
- macOS Mojave version 10.14.1
|
66
122
|
- docker-compose version 1.23.2, build 1110ad01
|