您好,应该在Ubuntu 20.04的Docker上直接安装Wordpress和PHPMyadmin,这会在STDOUT中引发错误,随后尝试在浏览器中查看WordPress时,我得到了一个非特定的数据库错误。
首先是我的Yaml文件:
version: '3'
services:
db:
image: mysql:8
container_name: mysql
restart: always
command: '--default-authentication-plugin=mysql_native_password'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wpdb
MYSQL_USER: user
MYSQL_PASSWORD: password
wordpress:
image: wordpress:5.4.1
container_name: wordpress
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_NAME: wpdb
WORDPRESS_USER: user
WORDPRESS_PASSWORD: password
ports:
- 8080:80
- 443:443
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 3333:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
And Now the output from **docker-compose up**
Starting mysql ... done
Starting test2_phpmyadmin_1 ... done
Starting wordpress ... done
Attaching to mysql, test2_phpmyadmin_1, wordpress
mysql | 2020-05-13 08:25:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
mysql | 2020-05-13 08:25:52+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
phpmyadmin_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.3. Set the 'ServerName' directive globally to suppress this message
mysql | 2020-05-13 08:25:52+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
mysql | 2020-05-13T08:25:52.527362Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
mysql | 2020-05-13T08:25:52.527443Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 1
phpmyadmin_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.3. Set the 'ServerName' directive globally to suppress this message
mysql | 2020-05-13T08:25:52.534595Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
phpmyadmin_1 | [Wed May 13 08:25:52.250991 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.5 configured -- resuming normal operations
phpmyadmin_1 | [Wed May 13 08:25:52.251029 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
mysql | 2020-05-13T08:25:52.671334Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql | 2020-05-13T08:25:52.773825Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
wordpress | [13-May-2020 08:25:52 UTC] PHP Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress |
wordpress | MySQL Connection Error: (2002) Connection refused
mysql | 2020-05-13T08:25:52.864314Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql | 2020-05-13T08:25:52.871773Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql | 2020-05-13T08:25:52.908753Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
wordpress | [13-May-2020 08:25:55 UTC] PHP Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'172.26.0.4' (using password: NO) in Standard input code on line 22
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | MySQL Connection Error: (1045) Access denied for user 'root'@'172.26.0.4' (using password: NO)
wordpress |
wordpress | WARNING: unable to establish a database connection to 'db'
wordpress | continuing anyways (which might have unexpected results)
wordpress |
wordpress | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.4. Set the 'ServerName' directive globally to suppress this message
wordpress | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.4. Set the 'ServerName' directive globally to suppress this message
wordpress | [Wed May 13 08:26:19.911848 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.17 configured -- resuming normal operations
wordpress | [Wed May 13 08:26:19.911906 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
正如我所说,当我尝试在 localhost:8080 上访问WordPress时,我得到了
建立数据库连接时出错
PhpMyadmin在 localhost:3333
上运行良好任何想法??????
哦,是的,我一直在关注本教程:https://www.youtube.com/watch?v=BfrVWwJv8ls
谢谢:)
答案 0 :(得分:1)
该错误表明WordPress无法连接到您的数据库容器。原因可能是由于WordPress不知道凭据,因为传递给WP容器的ENV变量未使用其期望的密钥。
如果您调整用于WP容器的密钥以匹配您在此处看到的密钥:https://docs.docker.com/compose/wordpress/,它将运行。像这样尝试:
version: '3'
services:
db:
image: mysql:8
container_name: mysql
restart: always
command: '--default-authentication-plugin=mysql_native_password'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wpdb
MYSQL_USER: user
MYSQL_PASSWORD: password
wordpress:
image: wordpress:5.4.1
container_name: wordpress
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wpdb
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
ports:
- 8080:80
- 443:443
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 3333:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
答案 1 :(得分:1)
这是我更新的代码:
version: '3'
services:
db:
image: mysql:8
volumes:
- ./db_data:/var/lib/mysql
container_name: mysql
restart: always
command: '--default-authentication-plugin=mysql_native_password'
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wpdb
MYSQL_USER: user
MYSQL_PASSWORD: password
wordpress:
image: wordpress:5.4.1
container_name: wordpress
restart: always
volumes:
- ./html:/var/www/html
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wpdb
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
ports:
- 8080:80
- 443:443
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 3333:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
volumes:
db_data: {}