dockerにおいてmysql接続に対するAccess deniedなどが発生し、docker コンテナが立ち上がらない
解決したいこと
dockerやnginxのリバースプロキシ、letsencryptを用いて構築しているUbuntuサーバーを再起動後、etherpadのdockerコンテナを立ち上げるとERROR: Problem while initalizing the databaseや Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'etherpad'@'172.24.0.3' (using password: YES)が出てコンテナを立ち上げることができません。
恐らくetherpadコンテナと同じネットワークに所属しているMySQLのコンテナが悪さをしていると考えていますが、実際にそうなのか?、またそうだとしても原因がわかりません。
どなたがインシデントの原因や解消方法がわかる方がいらっしゃいましたらご教授いただけますと幸いです。
サーバーの環境
OS Ubuntu20.04
docker snapでインストール 20.10.24
エラーの内容
docker compose upしてもetherpad_etherpadコンテナが立ち上がらない
当該するソースコード
docker-compose.yml
環境変数は、.envファイルから取得しています。
version: '3.8'
services:
etherpad:
image: etherpad/etherpad:latest
container_name: etherpad_etherpad
restart: always
volumes:
- etherpad:/opt/etherpad-lite
environment:
- VIRTUAL_HOST=etherpad
- ADMIN_PASSWORD=${ETHERPAD_ADMIN_PASSWORD}
- USER_PASSWORD=${ETHERPAD_USER_PASSWORD}
- DB_TYPE=mysql
- DB_HOST=db
- DB_PORT=3306
- DB_NAME=${MYSQL_DATABASE}
- DB_USER=${MYSQL_USER}
- DB_PASS=${MYSQL_PASSWORD}
- DB_CHARSET=xxxxxx
- SKIN_VARIANTS=light-toolbar super-dark-background super-light-editor full-width-editor
- REQUIRE_AUTHENTICATION=true
- TZ=Asia/Tokyo
networks:
- proxy-tier
- default
depends_on:
- db
healthcheck:
disable: true # disable any default healthcheck set by the image
db:
image: mariadb:latest
container_name: etherpad_db
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- TZ=Asia/Tokyo
volumes:
db:
name: etherpad_db
etherpad:
name: etherpad_etherpad
networks:
proxy-tier:
name: proxy-network
コマンド実行結果
docker compose upのエラーを見るとetherpad_etherpadコンテナでProblem while initalizing the databaseエラーが発生しています。またエラー前後のアクセスが禁止されていることがわかります。このアクセスの禁止もエラーの原因に繋がりそうですが、なぜ禁止されているかはわからないです。
docker compose up
出力結果 (一部)
etherpad_db | 2023-06-09 14:10:07+09:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.5+maria~focal started.
etherpad_db | 2023-06-09 14:10:08+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
etherpad_db | 2023-06-09 14:10:08+09:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.5+maria~focal started.
etherpad_db | 2023-06-09 14:10:08 0 [Note] mysqld (server 10.6.5-MariaDB-1:10.6.5+maria~focal) starting as process 1 ...
etherpad_db | 2023-06-09 14:10:08 0 [Warning] You need to use --log-bin to make --binlog-format work.
etherpad_db | 2023-06-09 14:10:08で 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
etherpad_db | 2023-06-09 14:10:08 0 [Note] InnoDB: Number of pools: 1
etherpad_db | 2023-06-09 14:10:08 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
etherpad_db | 2023-06-09 14:10:08 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
etherpad_db | 2023-06-09 14:10:08 0 [Note] InnoDB: Using Linux native AIO
etherpad_db | 2023-06-09 14:10:08 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
etherpad_db | 2023-06-09 14:10:08 0 [Note] InnoDB: Completed initialization of buffer pool
etherpad_db | 2023-06-09 14:10:08 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=1340015515,1340015515
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: 128 rollback segments are active.
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: Creating shared tablespace for temporary tables
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: 10.6.5 started; log sequence number 1340015527; transaction id 116932
etherpad_db | 2023-06-09 14:10:09 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
etherpad_db | 2023-06-09 14:10:09 0 [Note] Plugin 'FEEDBACK' is disabled.
etherpad_db | 2023-06-09 14:10:09 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
etherpad_db | 2023-06-09 14:10:09 0 [Note] Server socket created on IP: '0.0.0.0'.
etherpad_db | 2023-06-09 14:10:09 0 [Note] Server socket created on IP: '::'.
etherpad_db | 2023-06-09 14:10:09 0 [Warning] 'proxies_priv' entry '@% root@09127af349fb' ignored in --skip-name-resolve mode.
etherpad_etherpad | [2023-06-09 14:10:14.643] [INFO] server - Starting Etherpad...
etherpad_db | 2023-06-09 14:10:14 4 [Warning] Access denied for user 'e-user'@'172.24.0.3' (using password: YES)
etherpad_etherpad | [2023-06-09 14:10:14.672] [ERROR] console - ERROR: Problem while initalizing the database
etherpad_etherpad | [2023-06-09 14:10:14.672] [ERROR] console - Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'e-user'@'172.24.0.3' (using password: YES)
.
.
.
etherpad_etherpad exited with code 1
docker ps
出力結果
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
555f9a3bbcec etherpad/etherpad:latest "docker-entrypoint.s…" 16 minutes ago Restarting (1) 2 seconds ago etherpad_etherpad
05cc8dbe2d51 mariadb:latest "docker-entrypoint.s…" 16 minutes ago Up 8 seconds 3306/tcp etherpad_db
docker network ls
出力結果
[
{
"Name": "etherpad_default",
"Id": "bdd1095085716f0d5940764eed5fed2b11a10120c244e49045316fc05957f160",
"Created": "2023-06-09T13:39:00.789445888+09:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.24.0.0/16",
"Gateway": "172.24.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"05cc8dbe2d51887ac750aba884d8c51a98c0cd18b9fa51605d882d84c1923c2d": {
"Name": "etherpad_db",
"EndpointID": "45ca4806369f4000695e946dcb1f4ebcb5d37adb0fb8bf5dac127ff72b5935a5",
"MacAddress": "XX:XX:XX:XX:XX:XX",
"IPv4Address": "172.24.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "etherpad",
"com.docker.compose.version": "2.17.2"
}
}
]
自分で試したこと
etherpad_dbコンテナで発生していたincorrect definition of table mysql.event: expected column “definer” at position 3 to have type varchar(, found type char(141))エラーを当該するテーブルのコラムをvarcharに変更することで解消 → Problem while initalizing the databaseエラーは解消されず
docker exec -it etherpad_db bash
コマンドを実行し、etherpad_dbコンテナ内から
mysql -u e-user -p
コマンドで.envに記述しているパスワードを入力してmysqlサーバーにアクセスできることを確認
mysqlサーバーにアクセス後status
コマンドを実行
出力結果にportの欄がないことを確認 (今回のインシデントの原因である可能性がある?)
ホストPCで3306番ポートが開放されていることを確認
sudo ufw status
出力結果(一部)
3306 ALLOW 172.16.0.0/12
9001 ALLOW 172.16.0.0/12