我有一台使用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文件。这两个容器都在创建Traefik容器时指定的proxy
网络中运行。
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
答案 0 :(得分:0)
您在同一网络上拥有它,对于单个节点,您需要使其“取决于:db”。