MySQL5.7.30の公式Dockerイメージが動かない

いや、docker コマンド単体では確かに動きます。

しかし、docker compose すると動かなくなる…

どうやら同梱されている docker-entrypoint.sh に問題があるようです。

1回目の起動

mysql57-mysql-1  | 2023-03-03 10:20:08+09:00 [Note] [Entrypoint]: Stopping temporary server
mysql57-mysql-1  | mysqladmin: connect to server at 'localhost' failed
mysql57-mysql-1  | error: 'Can't connect to MySQL server on 'localhost' (99)'
mysql57-mysql-1  | Check that mysqld is running on localhost and that the port is 3306.
mysql57-mysql-1  | You can check this by doing 'telnet localhost 3306'
mysql57-mysql-1  | 2023-03-03 10:20:08+09:00 [ERROR] [Entrypoint]: Unable to shut down server.
mysql57-mysql-1 exited with code 1

サーバがエラー終了して、docker ps しても mysqld がいないことを確認。

2回目の起動

mysql57-mysql-1  | 2023-03-03T01:24:57.343584Z 0 [Note] mysqld: ready for connections.
mysql57-mysql-1  | Version: '5.7.30'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

サーバが正常に上がったように見えるが…

PS C:\Users\user\mysql5.7> docker-compose exec mysql bash
root@3b2cbd7999ea:/# mysql -uroot -p<パスワード>
ERROR 1045 (28000): Access denied for host '127.0.0.1' (using password: YES)

確かにローカルホストにアクセスしようとしても無理です。

Docker の MySQL オプションに関する記述を読むと、ホスト名を指定しないといけないらしい。

  mysql:
    image: mysql:5.7.30
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_HOST: '%'
      MYSQL_ROOT_PASSWORD: <パスワード>

今度はうまくいった。

root@3b2cbd7999ea:/tmp/common# mysql -uroot -p<パスワード>
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

ただし、初回起動に失敗するのは相変わらず。2回起動すれば動くので、本日は良しとします。

投稿者について
みのしす

小さいときは科学者になろうとしたのに、その時にたまたま身に着けたプログラミングで未だに飯を食っているしがないおじさんです。(年齢的にはもうすぐおじいさん)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です