建立数据库连接泊坞窗时出错 [英] Error establish a database connection docker compose
问题描述
我正在尝试使用 docker
设置 wordpress
。我在下面包含了我的yaml文件。在这里,我已经将mariadb_database设置为db_tyre。
I am trying to setup wordpress
with docker
. I have included my yaml file below. Here I have set my mariadb_database to db_tyre.
当我点击 docker-compose up -d
时,它正在创建所有需要的wordpress文件。这也在创建db_tyre数据库,但是当我尝试localhost:8000时,它给了我建立数据库连接时出现错误
。
When I hit docker-compose up -d
, it is creating all the required files of wordpress. This is also creating db_tyre database but when I try localhost:8000, it gives me Error establishing a database connection
.
我已经检查了wp-config.php文件,它具有以下几行。
I have checked the wp-config.php file, it has following lines.
define( 'DB_NAME', 'wordpress');
/** MySQL database username */
define( 'DB_USER', 'wordpress');
/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress');
/** MySQL hostname */
define( 'DB_HOST', 'mariadb:3306');
yml文件
yml file
version: '3'
services:
# Database
db:
image: bitnami/mariadb:latest
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MARIADB_ROOT_PASSWORD: password
MARIADB_DATABASE: db_tyre
MARIADB_USER: wordpress
MARIADB_PASSWORD: wordpress
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes: ['./:/var/www/html']
environment:
WORDPRESS_DB_HOST: mariadb:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:
推荐答案
如评论中所述,您应该设置更新 HOST
,但是仍然无法正常工作,因为WordPress DB配置似乎不正确。
As mentioned in the comment, you should set update the HOST
but still, it will not work, as the WordPress DB configuration does not seems correct.
数据库的ENV是
MARIADB_ROOT_PASSWORD: password
MARIADB_DATABASE: db_tyre
MARIADB_USER: wordpress
MARIADB_PASSWORD: wordpress
因此WordPress数据库配置应该更新,并且应该为 db_tyre
so the WordPress DB configuration should be updated and it should be db_tyre
define( 'DB_NAME', 'db_tyre');
/** MySQL database username */
define( 'DB_USER', 'wordpress');
/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress');
/** MySQL hostname */
define( 'DB_HOST', 'db:3306');
或可以尝试使用官方图像
or can try with offical image
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
这篇关于建立数据库连接泊坞窗时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!