gpt4 book ai didi

mysql - Docker wordpress/mysql 失败并显示 "connection refused"

转载 作者:行者123 更新时间:2023-11-29 09:41:04 34 4
gpt4 key购买 nike

我正在尝试设置环境来构建 WordPress 站点,但 docker-compose 失败并拒绝连接。

我花了两天多的时间试图弄清楚,浏览网页但徒劳无功。我尝试了堆栈溢出上可用的解决方案,但仍然徒劳。

这是我的 docker-compose

version: '3.7'
services:
wordpress:
depends_on:
- db
image: wordpress
container_name: wp-web
ports:
- 7000:80
restart: unless-stopped
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: banana
WORDPRESS_DB_PASSWORD: banana
WORDPRESS_DB_NAME: banana
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
db:
image: mysql:5.7
container_name: db_server
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./db_data:/home/abelmbula/Documents/dockerapp/lib/mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: banana
MYSQL_DATABASE: banana
MYSQL_USER: banana
MYSQL_PASSWORD: banana
ports:
- 8889:3306
volumes:
db_data:

我得到了这个输出

Starting db_server ... done
Recreating wp-web ... done
Attaching to db_server, wp-web
db_server | Initializing database
db_server | 2019-06-14T13:32:53.477264Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_server | 2019-06-14T13:32:53.479113Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
db_server | 2019-06-14T13:32:53.479146Z 0 [ERROR] Aborting
db_server |
wp-web | [14-Jun-2019 13:33:03 UTC] PHP Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wp-web |
wp-web | MySQL Connection Error: (2002) Connection refused
db_server exited with code 1

我上面的文件有问题吗?

最佳答案

这是一个最小的例子:

version: '3.7'
services:
wordpress:
depends_on:
- mysql
image: wordpress
container_name: wordpress
hostname: wordpress
domainname: example.com
ports:
- 8080:80
restart: unless-stopped
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: banana
WORDPRESS_DB_PASSWORD: banana
WORDPRESS_DB_NAME: banana
working_dir: /var/www/html
volumes:
- wp_content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
mysql:
image: mysql:5.7
container_name: mysql
hostname: mysql
domainname: example.com
command: --default-authentication-plugin=mysql_native_password
volumes:
- db_data:/var/lib/mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: banana
MYSQL_DATABASE: banana
MYSQL_USER: banana
MYSQL_PASSWORD: banana
expose:
- 3306
volumes:
db_data:
wp_content:

此示例使用 db_data volumes 中定义的体积为了存储数据库文件(默认情况下 docker 卷存在于主机操作系统上的 /var/lib/docker/volumes 中),它添加了一个名为 docker volume 的文件。对于wordpress内容,它不会将数据库端口发布到主机,而是将其公开在 docker 中网络使wordpress服务可以访问它并设置示例 hostnamedomainname服务条目。

关于mysql - Docker wordpress/mysql 失败并显示 "connection refused",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56599953/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com