mysql - WordPress Docker 容器无法连接到 MySQL 容器
问题描述
我有一个使用 Traefik 处理前端的服务器,并且我已经设置了一个 WordPress/MySQL 设置来尝试运行一个博客。但是,Wordpress 容器抛出以下错误:
[12-Sep-2020 04:17:14 UTC] PHP Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'my_name'@'172.19.0.5' (using password: YES) in Standard input code on line 22
MySQL Connection Error: (1045) Access denied for user 'my_name'@'172.19.0.5' (using password: YES)
(this error message repeats several times)
WARNING: unable to establish a database connection to 'db'
continuing anyways (which might have unexpected results)
[Sat Sep 12 04:17:41.602702 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.10 configured -- resuming normal operations
[Sat Sep 12 04:17:41.602774 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
这是用于 Wordpress/MySQL 设置的 docker-compose.yml 文件。两个容器都在proxy
创建 Traefik 容器时指定的网络中运行。
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: database
volumes:
- wordpress:/var/www/html
networks:
- proxy
labels:
- "traefik.enable=true"
- "traefik.http.routers.wordpress.entrypoints=http"
- "traefik.http.routers.wordpress.rule=Host(`catblog.cf`)"
- "traefik.http.routers.wordpress.middlewares=https-redirect@file"
- "traefik.http.routers.wordpress-secure.entrypoints=https"
- "traefik.http.routers.wordpress-secure.rule=Host(`catblog.cf`)"
- "traefik.http.routers.wordpress-secure.tls=true"
- "traefik.http.routers.wordpress-secure.tls.certresolver=http"
- "traefik.http.routers.wordpress-secure.service=wordpress"
- "traefik.http.services.wordpress.loadbalancer.server.port=9000"
- "traefik.docker.network=proxy"
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: db_username
MYSQL_PASSWORD: db_password
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
networks:
- proxy
labels:
- "traefik.enable=true"
- "traefik.http.routers.mysql.entrypoints=http"
- "traefik.http.routers.mysql.middlewares=https-redirect@file"
- "traefik.http.routers.mysql-secure.entrypoints=https"
- "traefik.http.routers.mysql-secure.tls=true"
- "traefik.http.routers.mysql-secure.tls.certresolver=http"
- "traefik.http.routers.mysql-secure.service=mysql"
- "traefik.http.services.mysql.loadbalancer.server.port=9000"
- "traefik.docker.network=proxy"
volumes:
wordpress:
db:
networks:
proxy:
external: true
解决方案
您在同一个网络上拥有它,对于单个节点,您需要拥有它“取决于:db”。
推荐阅读
- reactjs - React Material UI 表格排序
- python - 如何使用python中的键盘模块模拟向上键?
- python - Download fails with "Authentication failed" when we try to download 50+ files from SFTP serially using pysftp in Python?
- windows - 如何在整个文件夹结构中使用包含特定字符串的批处理脚本查找文件?
- mvvm - 在没有 Cesium.knockout 的情况下更改 cesium 模型的属性时如何实时更新视图
- ethereum - 如何在智能合约中编写开始彩票
- flutter - 如何使用 Flutter 检查和检索空的双精度值
- android - 如何在android中以编程方式读取persistent_properties文件
- c# - 如何获得记录属性的智能感知?
- python - Tensorflow 数据集在 take() 中拆分为输入和标签