我将docker-compose.yaml文件更改为以下内容:
version: '3.8'
services:
MySQL:
container_name: MySQL
image: mysql:8.0.19
ports:
- "3306:3306"
volumes:
- mysql-volume:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: pskPSK258##
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: pskPSK258##
command: --default-authentication-plugin=mysql_native_password
wordpress:
depends_on:
- MySQL
container_name: WordPresss
image: wordpress:5.4.0-php7.4-fpm-alpine
ports:
- "8000:80"
volumes:
- wordpress-volume:/var/www/html
restart: always
environment:
WORDPRESS_DB_HOST: MySQL:3306
WORDPRESS_DB_NAME: wordpress
WORDPRESS_TABLE_PREFIX: tbl
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: pskPSK258##
volumes:
mysql-volume:
name: mysql-volume
driver: local
wordpress-volume:
name: wordpress-volume
driver: local
我仍然遇到与以前相同的问题,但是当我使用wordpress:5.4.0-php7.4(不使用Alpine)时,连接没有问题。是什么原因呢?