[英]Docker WordPress image can't connect to database
I have an issue with a docker image.我有一个 docker 图像的问题。
I have just followed this tutorial to get custom local domains: https://medium.com/@francoisromain/set-a-local-web-development-environment-with-custom-urls-and-https-3fbe91d2eaf0我刚刚按照本教程获取自定义本地域: https : //medium.com/@francoisromain/set-a-local-web-development-environment-with-custom-urls-and-https-3fbe91d2eaf0
This seem to work good.这似乎效果很好。 But now I can not seem to connect to the Mysql database.
但是现在好像连接不上Mysql数据库了。
I'm using the WordPress image and my docker-compose.yml file looks like this:我正在使用 WordPress 图像,我的 docker-compose.yml 文件如下所示:
version: '3.3'
services:
db:
image: mysql:5.7
restart: unless-stopped
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: p4ssw0rd!
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
expose:
- 80
environment:
VIRTUAL_HOST: phpmyadmin.local
VIRTUAL_PORT: 80
PMA_HOST: db
MYSQL_ROOT_PASSWORD: p4ssw0rd!
wordpress:
depends_on:
- db
image: wordpress:latest
restart: unless-stopped
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
restart: always
expose:
- 80
environment:
VIRTUAL_HOST: domain.local
VIRTUAL_PORT: 80
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wp_name
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: p4ssw0rd!
WORDPRESS_TABLE_PREFIX: wp_
WORDPRESS_DEBUG: 1
volumes:
db_data: {}
networks:
default:
external:
name: nginx-proxy
When I start running the container, the error I'm getting is this:当我开始运行容器时,我得到的错误是这样的:
So now I know my WordPress container and proxy are working (domain.local), but the only thing missing is the connection to the database.
所以现在我知道我的 WordPress 容器和代理正在工作 (domain.local),但唯一缺少的是与数据库的连接。
I think this has to do with the 'network' and that he simply can't find the database.我认为这与“网络”有关,而他根本找不到数据库。 But I have no idea how to connect it.
但我不知道如何连接它。
Hope one of you guys know what I'm doing wrong.希望你们中的一个人知道我做错了什么。 Thanks in advance.
提前致谢。
Okay, so I finally figured it out.好吧,所以我终于想通了。
The WORDPRESS_DB_USER
should be set to: root WORDPRESS_DB_USER
应设置为:root
Then everything will work.然后一切都会好起来的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.