概要
ご覧いただきありがとうございます。
丸1日以上の調査の結果、 docker compose -p test up -d --build
時の wp-config.php
ファイルの生成に問題がありそうと考えていますが、どうしても原因がわからず、皆様のお力をお貸しいただきたいです。
今回要因の一つになっていることが推測されるwp-config.php
php
1<?php 2/** 3 * The base configuration for WordPress 4 * 5 * The wp-config.php creation script uses this file during the installation. 6 * You don't have to use the web site, you can copy this file to "wp-config.php" 7 * and fill in the values. 8 * 9 * This file contains the following configurations: 10 * 11 * * MySQL settings 12 * * Secret keys 13 * * Database table prefix 14 * * ABSPATH 15 * 16 * This has been slightly modified (to read environment variables) for use in Docker. 17 * 18 * @link https://wordpress.org/support/article/editing-wp-config-php/ 19 * 20 * @package WordPress 21 */ 22 23// IMPORTANT: this file needs to stay in-sync with https://github.com/WordPress/WordPress/blob/master/wp-config-sample.php 24// (it gets parsed by the upstream wizard in https://github.com/WordPress/WordPress/blob/f27cb65e1ef25d11b535695a660e7282b98eb742/wp-admin/setup-config.php#L356-L392) 25 26// a helper function to lookup "env_FILE", "env", then fallback 27if (!function_exists('getenv_docker')) { 28 // https://github.com/docker-library/wordpress/issues/588 (WP-CLI will load this file 2x) 29 function getenv_docker($env, $default) { 30 if ($fileEnv = getenv($env . '_FILE')) { 31 return rtrim(file_get_contents($fileEnv), "\r\n"); 32 } 33 else if (($val = getenv($env)) !== false) { 34 return $val; 35 } 36 else { 37 return $default; 38 } 39 } 40} 41 42// ** MySQL settings - You can get this info from your web host ** // 43/** The name of the database for WordPress */ 44define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'wordpress') ); 45 46/** MySQL database username */ 47define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'example username') ); 48 49/** MySQL database password */ 50define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'example password') ); 51 52/** 53 * Docker image fallback values above are sourced from the official WordPress installation wizard: 54 * https://github.com/WordPress/WordPress/blob/f9cc35ebad82753e9c86de322ea5c76a9001c7e2/wp-admin/setup-config.php#L216-L230 55 * (However, using "example username" and "example password" in your database is strongly discouraged. Please use strong, random credentials!) 56 */ 57 58/** MySQL hostname */ 59define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql') ); 60 61/** Database charset to use in creating database tables. */ 62define( 'DB_CHARSET', getenv_docker('WORDPRESS_DB_CHARSET', 'utf8') ); 63 64/** The database collate type. Don't change this if in doubt. */ 65define( 'DB_COLLATE', getenv_docker('WORDPRESS_DB_COLLATE', '') ); 66 67/**#@+ 68 * Authentication unique keys and salts. 69 * 70 * Change these to different unique phrases! You can generate these using 71 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}. 72 * 73 * You can change these at any point in time to invalidate all existing cookies. 74 * This will force all users to have to log in again. 75 * 76 * @since 2.6.0 77 */ 78define( 'AUTH_KEY', getenv_docker('WORDPRESS_AUTH_KEY', '2254296a55ca23263007c0028b03d61150895349') ); 79define( 'SECURE_AUTH_KEY', getenv_docker('WORDPRESS_SECURE_AUTH_KEY', 'b60fd478500e5f253072e6ca54177089a0dbe5dd') ); 80define( 'LOGGED_IN_KEY', getenv_docker('WORDPRESS_LOGGED_IN_KEY', 'f8fd9866fd51ee0388b5c7bfdcaf674a86e2a49d') ); 81define( 'NONCE_KEY', getenv_docker('WORDPRESS_NONCE_KEY', '67d99a340e071d11a7d2d7b8623f3d6b62c5e2b3') ); 82define( 'AUTH_SALT', getenv_docker('WORDPRESS_AUTH_SALT', '4b23626cc9644cbedb152b4143bbfee1402a77d6') ); 83define( 'SECURE_AUTH_SALT', getenv_docker('WORDPRESS_SECURE_AUTH_SALT', 'e0563d3ac0c5639270c9bf5c3fa266339eef91db') ); 84define( 'LOGGED_IN_SALT', getenv_docker('WORDPRESS_LOGGED_IN_SALT', 'c9a546581ab2304c0c9cd1e3c242725f464d37bc') ); 85define( 'NONCE_SALT', getenv_docker('WORDPRESS_NONCE_SALT', 'bba66e2b3beded52a678e2008d8306a1ac9f6f09') ); 86// (See also https://wordpress.stackexchange.com/a/152905/199287) 87 88/**#@-*/ 89 90/** 91 * WordPress database table prefix. 92 * 93 * You can have multiple installations in one database if you give each 94 * a unique prefix. Only numbers, letters, and underscores please! 95 */ 96$table_prefix = getenv_docker('WORDPRESS_TABLE_PREFIX', 'wp_'); 97 98/** 99 * For developers: WordPress debugging mode. 100 * 101 * Change this to true to enable the display of notices during development. 102 * It is strongly recommended that plugin and theme developers use WP_DEBUG 103 * in their development environments. 104 * 105 * For information on other constants that can be used for debugging, 106 * visit the documentation. 107 * 108 * @link https://wordpress.org/support/article/debugging-in-wordpress/ 109 */ 110define( 'WP_DEBUG', !!getenv_docker('WORDPRESS_DEBUG', '') ); 111 112/* Add any custom values between this line and the "stop editing" line. */ 113 114// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact 115// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy 116if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { 117 $_SERVER['HTTPS'] = 'on'; 118} 119// (we include this by default because reverse proxying is extremely common in container environments) 120 121if ($configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '')) { 122 eval($configExtra); 123} 124 125/* That's all, stop editing! Happy publishing. */ 126 127/** Absolute path to the WordPress directory. */ 128if ( ! defined( 'ABSPATH' ) ) { 129 define( 'ABSPATH', __DIR__ . '/' ); 130} 131 132/** Sets up WordPress vars and included files. */ 133require_once ABSPATH . 'wp-settings.php';
発生している問題・エラー
docker compose -p test up -d --build
すると、下記のようにdbのみ上手く立ち上がりません。
NAME SERVICE STATUS PORTS test_dev_db db restarting test_dev_mailhog mailhog running 127.0.0.2:1025->1025/tcp, 127.0.0.2:8025->8025/tcp test_dev_pma phpmyadmin running 127.0.0.2:8080->80/tcp test_dev_wp wordpress running 127.0.0.2:80->80/tcp, 127.0.0.2:443->443/tcp
docker-compose.yml
で restart: always
を指定しているため、runningとrestartingを繰り返している状態です。
docker logs test_dev_db
をした結果は、下記の通りです。
2021-06-18 06:33:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. 2021-06-18 06:33:51+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2021-06-18 06:33:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started. 2021-06-18 06:33:51+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user Remove MYSQL_USER="root" and use one of the following to control the root user password: - MYSQL_ROOT_PASSWORD - MYSQL_ALLOW_EMPTY_PASSWORD - MYSQL_RANDOM_ROOT_PASSWORD
エラー文の提案通り、下記を変更すると立ち上がるようにはなりますが、 dev.test.com へアクセスすると「データベース接続確立エラー」の表示となってしまいます。
.env
の MYSQL_USER
を root
から user
へ変更
docker-compose.yml の MYSQL_USER
と MYSQL_PASSWORD
をコメントアウト
解決したいこと
docker compose -p test up -d --build
した際、上に挙げた「今回要因の一つになっていることが推測されるwp-config.php」ではなく、「正常に動いていた以前のwp-config.php」のようなwp-config.phpが生成され、且つブラウザからアクセスできるように戻したいです。
ちなみにもう一台のデバイスでも試しましたが、そちらは同じ環境で正常に動いております。
ぜひお知恵をお貸しいただければ幸いでございます。
(字数の関係で環境で情報が足りない場合は、ご質問ください。)
あなたの回答
tips
プレビュー