環境Ubuntu 20.04
docker でswarmクラスタでマネージャーノード2台ワーカーノード2台で構成しています。
docker-compose.ymlでWordpressサービスを立ち上げて、プラウザでアクセスしたら以下のエラー発生しました。
Error establishing a database connection
最初のYAMLファイルです。
ersion: '3.4' #composeファイルのバージョン services: wrodpress: image: wordpress ports: - 8080:80 environment: WORDPRESS_DB_PASSWORD: samplewp #Wordpressで使用するDBのパスワードを指定 deploy: replicas: 2 placement: constraints: - node.role == worker depends_on: - mysql mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: samplewp volumes: - mysql_Vol:var/lib/mysql deploy: replicas: 1 placement: constraints: - node.hostname == manager1 volumes: mysql_vol:
調べたら、 WORDPRESS_DB_HOST:mysqlを記述すれば解決したという記事を発見しそれを元に上のYAMLファイルを修正しました。
environment: WORDPRESS_DB_HOST: mysql WORDPRESS_DB_PASSWORD: samplewp
一度作成したWordpressとDBを削除して
docker stack deploy --compose-file docker-compose.yml wpを実行してプラウザからアクセスしましたが変化がありません。
docker service logs wp_wrodpressコマンドを実行してログを確認しました。
WordPress not found in /var/www/html - copying now... wp_wrodpress.1.0b2qv88d9qaa@worker1 | Complete! WordPress has been successfully copied to /var/www/html wp_wrodpress.1.0b2qv88d9qaa@worker1 | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_PASSWORD) wp_wrodpress.1.0b2qv88d9qaa@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.25. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.1.0b2qv88d9qaa@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.25. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.1.0b2qv88d9qaa@worker1 | [Mon Apr 05 20:17:50.637531 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.16 configured -- resuming normal operations wp_wrodpress.1.0b2qv88d9qaa@worker1 | [Mon Apr 05 20:17:50.638032 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' wp_wrodpress.1.0b2qv88d9qaa@worker1 | 10.0.0.2 - - [05/Apr/2021:20:18:03 +0000] "GET /favicon.ico HTTP/1.1" 500 2834 "http://192.168.99.111:8080/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0" wp_wrodpress.2.s636ciu26koj@worker1 | WordPress not found in /var/www/html - copying now... wp_wrodpress.2.s636ciu26koj@worker1 | Complete! WordPress has been successfully copied to /var/www/html wp_wrodpress.2.s636ciu26koj@worker1 | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_PASSWORD) wp_wrodpress.2.s636ciu26koj@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.26. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.2.s636ciu26koj@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.26. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.2.s636ciu26koj@worker1 | [Mon Apr 05 20:17:50.633778 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.16 configured -- resuming normal operations wp_wrodpress.2.s636ciu26koj@worker1 | [Mon Apr 05 20:17:50.634552 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' wp_wrodpress.2.s636ciu26koj@worker1 | 10.0.0.2 - - [05/Apr/2021:20:18:02 +0000] "GET / HTTP/1.1" 500 2834 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0" wp_wrodpress.2.s636ciu26koj@worker1 | 10.
いろいろ調べて以下のように修正しました。
version: '3.4' services: wrodpress: image: wordpress ports: - 8000:80 restart: always environment: WORDPRESS_DB_HOST: mysql WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: samplewp deploy: replicas: 2 placement: constraints: - node.role == worker depends_on: - mysql mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWROD: samplewp volumes: - mysql_vol:/var/lib/mysql deploy: replicas: 1 placement: constraints: - node.hostname == manager1 volumes: mysql_vol: ~
しかし、プラウザでは未だ、「Error establishing a database connection」と表示され変わりません。
docker service logs wb_wordpressの実行結果は
aito@saito:~$ docker service logs wp_wrodpress wp_wrodpress.1.5tt871tjgpid@worker1 | WordPress not found in /var/www/html - copying now... wp_wrodpress.1.5tt871tjgpid@worker1 | Complete! WordPress has been successfully copied to /var/www/html wp_wrodpress.1.5tt871tjgpid@worker1 | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER) wp_wrodpress.1.5tt871tjgpid@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.77. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.1.5tt871tjgpid@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.77. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.1.5tt871tjgpid@worker1 | [Tue Apr 06 09:59:29.530792 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.16 configured -- resuming normal operations wp_wrodpress.1.5tt871tjgpid@worker1 | [Tue Apr 06 09:59:29.531345 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' wp_wrodpress.2.m9kttpai6f2l@worker1 | WordPress not found in /var/www/html - copying now... wp_wrodpress.2.m9kttpai6f2l@worker1 | Complete! WordPress has been successfully copied to /var/www/html wp_wrodpress.2.m9kttpai6f2l@worker1 | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER) wp_wrodpress.2.m9kttpai6f2l@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.78. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.2.m9kttpai6f2l@worker1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.78. Set the 'ServerName' directive globally to suppress this message wp_wrodpress.2.m9kttpai6f2l@worker1 | [Tue Apr 06 09:59:29.515967 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.16 configured -- resuming normal operations wp_wrodpress.2.m9kttpai6f2l@worker1 | [Tue Apr 06 09:59:29.518052 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
変化はありません。
mysqlのログです。
wp_mysql.1.s6yobt9glaca@manager1 | 2021-04-07 00:00:05+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.33-1debian10 started. wp_mysql.1.s6yobt9glaca@manager1 | 2021-04-07 00:00:05+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' wp_mysql.1.s6yobt9glaca@manager1 | 2021-04-07 00:00:05+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。