docker-启动 wordpress 和 mysql 容器连接出错
首先去给 mysql 数据库创建对应的库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 root@ubuntu-server:~# docker inspect 6b07fc530884 | grep "IPAddress" "SecondaryIPAddresses": null, "IPAddress": "", "IPAddress": "172.18.0.2", root@ubuntu-server:~# mysql -h 172.18.0.2 -u root -p 123456 Enter password: ERROR 1049 (42000): Unknown database '123456' root@ubuntu-server:~# mysql -h 172.18.0.2 -u root -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 81 Server version: 8.3.0 MySQL Community Server - GPL Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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> show databases; +--------------------+ | Database | +--------------------+ | db_in_opt | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.03 sec) mysql> create database wordpressdb; Query OK, 1 row affected (0.02 sec) mysql> exit ;Bye root@ubuntu-server:~#
如果还有问题:
检查这个 wp-config.php 文件手动改成这样子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 root@ubuntu-server:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fe7e697cc62f wordpress "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:82->80/tcp, :::82->80/tcp hungry_dirac 6b07fc530884 mysql "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 3306/tcp, 33060/tcp flamboyant_lichterman root@ubuntu-server:~# docker inspect fe7e697cc62f | grep -A 10 "Mounts" "Mounts": [ { "Type": "volume", "Name": "a5071bea0ad386159c64d54a3353b6614fe4cef2de943ed1d2c9b55f87ef4c59", "Source": "/var/lib/docker/volumes/a5071bea0ad386159c64d54a3353b6614fe4cef2de943ed1d2c9b55f87ef4c59/_data", "Destination": "/var/www/html", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } root@ubuntu-server:~# cd /var/lib/docker/volumes/a5071bea0ad386159c64d54a3353b6614fe4cef2de943ed1d2c9b55f87ef4c59/_data/ root@ubuntu-server:/var/lib/docker/volumes/a5071bea0ad386159c64d54a3353b6614fe4cef2de943ed1d2c9b55f87ef4c59/_data# ll total 260 drwxr-xr-x 5 www-data www-data 4096 Jan 26 18:44 ./ drwx-----x 3 root root 4096 Jan 26 18:44 ../ -rw-r--r-- 1 www-data www-data 261 Jan 20 00:51 .htaccess -rw-r--r-- 1 www-data www-data 405 Feb 6 2020 index.php -rw-r--r-- 1 www-data www-data 19915 Jan 1 2023 license.txt -rw-r--r-- 1 www-data www-data 7399 Jul 5 2023 readme.html -rw-r--r-- 1 www-data www-data 7211 May 12 2023 wp-activate.php drwxr-xr-x 9 www-data www-data 4096 Dec 6 16:25 wp-admin/ -rw-r--r-- 1 www-data www-data 351 Feb 6 2020 wp-blog-header.php -rw-r--r-- 1 www-data www-data 2323 Jun 14 2023 wp-comments-post.php -rw-r--r-- 1 www-data www-data 5491 Jan 20 00:49 wp-config-docker.php -rw-r--r-- 1 www-data www-data 5595 Jan 26 18:44 wp-config.php -rw-r--r-- 1 www-data www-data 3013 Nov 15 17:47 wp-config-sample.php drwxr-xr-x 5 www-data www-data 4096 Dec 6 16:25 wp-content/ -rw-r--r-- 1 www-data www-data 5638 May 30 2023 wp-cron.php drwxr-xr-x 27 www-data www-data 16384 Dec 6 16:25 wp-includes/ -rw-r--r-- 1 www-data www-data 2502 Nov 26 2022 wp-links-opml.php -rw-r--r-- 1 www-data www-data 3927 Jul 16 2023 wp-load.php -rw-r--r-- 1 www-data www-data 50924 Sep 29 22:01 wp-login.php -rw-r--r-- 1 www-data www-data 8525 Sep 16 06:50 wp-mail.php -rw-r--r-- 1 www-data www-data 26409 Oct 10 14:05 wp-settings.php -rw-r--r-- 1 www-data www-data 34385 Jun 19 2023 wp-signup.php -rw-r--r-- 1 www-data www-data 4885 Jun 22 2023 wp-trackback.php -rw-r--r-- 1 www-data www-data 3154 Sep 30 07:39 xmlrpc.php root@ubuntu-server:/var/lib/docker/volumes/a5071bea0ad386159c64d54a3353b6614fe4cef2de943ed1d2c9b55f87ef4c59/_data# nano wp-config.php
更新: 2024-01-27 03:19:08 原文: https://www.yuque.com/zacharyblock/cx2om6/tag9c4g1eq7g2v17
Author:
Zachary Block
Permalink:
http://blockzachary.cn/blog/647255678/
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE