180603 Docker WordPress MySQL Error
開発環境
macOS High Sierra 10.13.4
Docker Community Edition Version 18.03.1-ce
https://tech.recruit-mp.co.jp/infrastructure/post-11266/
Step.2 ) まっさらな WordPress × MySQL 環境を構築
の通りのymlファイルに、WordPressとMySQLのバージョンを指定した
wordpress:4.9-php7.0-apache
mysql:5.5
code:docker-compose.yml
version: "2"
services:
wordpress:
image: wordpress:4.9-php7.0-apache
ports:
- "9000:80"
depends_on:
- db
environment:
WORDPRESS_DB_HOST: "db:3306"
env_file: .env
db:
image: mysql:5.5
env_file: .env
volumes:
- db-data:/var/lib/mysql
# databaseのように永続的なストレージが欲しい場合に必要な設定
# https://docs.docker.com/compose/compose-file/#volume-configuration-reference
volumes:
db-data:
.envファイルは変更なし
code:.env
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=wp_user
WORDPRESS_DB_PASSWORD=hogehoge
MYSQL_RANDOM_ROOT_PASSWORD=yes
MYSQL_DATABASE=wordpress
MYSQL_USER=wp_user
MYSQL_PASSWORD=hogehoge
ターミナルで、docker-compose up -d
Starting ${プロジェクト名}_db_1 ... done
Starting ${プロジェクト名}_wordpress_1 ... done
Chromeで、http://localhost:9000/にアクセスするが、
このサイトにアクセスできません
localhost で接続が拒否されました。
表示されないX_X
docker-compose stop
docker-compose down
をした後、
docker-compose upを試みる
Creating network "${プロジェクト名}_default" with the default driver
Creating ${プロジェクト名}_db_1 ... done
Creating ${プロジェクト名}_wordpress_1 ... done
Attaching to ${プロジェクト名}_db_1, ${プロジェクト名}_wordpress_1
db_1 | 180603 13:41:44 Note --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
db_1 | 180603 13:41:44 Note mysqld (mysqld 5.5.60) starting as process 1 ...
wordpress_1 | WordPress not found in /var/www/html - copying now...
db_1 | 180603 13:41:45 Note Plugin 'FEDERATED' is disabled.
db_1 | mysqld: Table 'mysql.plugin' doesn't exist
db_1 | 180603 13:41:45 ERROR Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
db_1 | 180603 13:41:45 InnoDB: The InnoDB memory heap is disabled
db_1 | 180603 13:41:45 InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 180603 13:41:45 InnoDB: Compressed tables use zlib 1.2.3
db_1 | 180603 13:41:45 InnoDB: Using Linux native AIO
db_1 | 180603 13:41:45 InnoDB: Initializing buffer pool, size = 128.0M
db_1 | 180603 13:41:45 InnoDB: Completed initialization of buffer pool
db_1 | InnoDB: Error: checksum mismatch in data file ./ibdata1
db_1 | 180603 13:41:45 InnoDB: Could not open or create data files.
db_1 | 180603 13:41:45 InnoDB: If you tried to add new data files, and it failed here,
db_1 | 180603 13:41:45 InnoDB: you should now edit innodb_data_file_path in my.cnf back
db_1 | 180603 13:41:45 InnoDB: to what it was, and remove the new ibdata files InnoDB created
db_1 | 180603 13:41:45 InnoDB: in this failed attempt. InnoDB only wrote those files full of
db_1 | 180603 13:41:45 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
db_1 | 180603 13:41:45 InnoDB: remove old data files which contain your precious data!
db_1 | 180603 13:41:45 ERROR Plugin 'InnoDB' init function returned error.
db_1 | 180603 13:41:45 ERROR Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
db_1 | 180603 13:41:45 ERROR Unknown/unsupported storage engine: InnoDB
db_1 | 180603 13:41:45 ERROR Aborting
db_1 |
db_1 | 180603 13:41:45 Note mysqld: Shutdown complete
db_1 |
${プロジェクト名}_db_1 exited with code 1
wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
^[[1;2wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
^R
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
${プロジェクト名}_wordpress_1 exited with code 1
コンテナごとのエラーの確認
$ docker logs 0fbc711dcbb0(WordPress)
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
$ docker logs a1be06dbee34(MySQL)
180603 13:41:44 Note --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
180603 13:41:44 Note mysqld (mysqld 5.5.60) starting as process 1 ...
180603 13:41:45 Note Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
180603 13:41:45 ERROR Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
180603 13:41:45 InnoDB: The InnoDB memory heap is disabled
180603 13:41:45 InnoDB: Mutexes and rw_locks use GCC atomic builtins
180603 13:41:45 InnoDB: Compressed tables use zlib 1.2.3
180603 13:41:45 InnoDB: Using Linux native AIO
180603 13:41:45 InnoDB: Initializing buffer pool, size = 128.0M
180603 13:41:45 InnoDB: Completed initialization of buffer pool
InnoDB: Error: checksum mismatch in data file ./ibdata1
180603 13:41:45 InnoDB: Could not open or create data files.
180603 13:41:45 InnoDB: If you tried to add new data files, and it failed here,
180603 13:41:45 InnoDB: you should now edit innodb_data_file_path in my.cnf back
180603 13:41:45 InnoDB: to what it was, and remove the new ibdata files InnoDB created
180603 13:41:45 InnoDB: in this failed attempt. InnoDB only wrote those files full of
180603 13:41:45 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
180603 13:41:45 InnoDB: remove old data files which contain your precious data!
180603 13:41:45 ERROR Plugin 'InnoDB' init function returned error.
180603 13:41:45 ERROR Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
180603 13:41:45 ERROR Unknown/unsupported storage engine: InnoDB
180603 13:41:45 ERROR Aborting
180603 13:41:45 Note mysqld: Shutdown complete
解決
suinさんより
db-dataボリュームが壊れている可能性がある
以下、https://hackmd.io/piL91DjISfacd_3M7Ds4tg そのまま引用
docker-composeで起動中コンテナを止める
docker-compose stop
いったんコンテナを消す
docker-compose rm
当該db-dataボリュームを探す
docker volume ls | grep db-data
local beco-wp_db-data
当該db-dataボリュームを削除する
docker volume rm beco-wp_db-data
docker-composeで起動しなおす
docker-compose up