简体   繁体   English

docker wordpress容器无法连接到数据库容器

[英]docker wordpress container can't connect to database container

I've been using docker to build wordpress apps for some days. 我已经使用docker来构建wordpress应用程序已有几天了。 I got some working but now I don't know why I can get to connect the database container and the wordpress container. 我有一些工作,但现在我不知道为什么我可以连接数据库容器和wordpress容器。

I've reduced the failing condiguration to the simplest possible. 我已经将失败的配置减少到最简单的可能性。

Right now I have the following docker-compose.yml file: 现在我有以下docker-compose.yml文件:

wordpress:
  image: wordpress
  links:
    - db:mysql
  ports:
    - 8080:80

db:
  image: mariadb
  environment:
    MYSQL_ROOT_PASSWORD: example

which is an exact copy of this official example: 这是这个官方例子的精确副本:

https://hub.docker.com/_/wordpress/ https://hub.docker.com/_/wordpress/

(scroll down to "... via docker-compose"). (向下滚动到“...通过docker-compose”)。

If I do composer up with this file I got the following relevant log entries: 如果我用这个文件作曲,我得到了以下相关的日志条目:

Creating miqueladell_db_1
Creating miqueladell_wordpress_1
Attaching to miqueladell_db_1, miqueladell_wordpress_1
db_1        | Initializing database

…lots of initialization… ......很多初始化......

wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10

…this goes on for a while, db_1 says it's initializing and wordpress_1 says it can connect and then… ......这种情况持续了一段时间,db_1说它正在初始化,而wordpress_1说它可以连接然后......

db_1        | MySQL init process done. Ready for start up.

…some more database messages… ......一些更多的数据库消息......

db_1        | 2016-01-12 14:34:46 139698309449664 [Note] mysqld: ready for connections.
wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.5. Set the 'ServerName' directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.5. Set the 'ServerName' directive globally to suppress this message
wordpress_1 | [Tue Jan 12 14:34:47.180996 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.17 configured -- resuming normal operations
wordpress_1 | [Tue Jan 12 14:34:47.181253 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

…at that momment if I browse to the wordpress endpoint I got… ...在那个妈妈,如果我浏览wordpress端点我得到...

wordpress_1 | 192.168.99.1 - - [12/Jan/2016:14:34:47 +0000] "GET / HTTP/1.1" 500 586 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"

And an Error establishing a database connection on the front end. 并且在前端建立数据库连接出错

I've pasted the full log here in case someone want's to take a look: http://pastebin.com/Z9U2iMsH 我已经粘贴了完整的日志,以防万一有人想看一看: http//pastebin.com/Z9U2iMsH

I've got my environment running before and I am sure that if not this particular example I have been able to run the containers and connect to the database with some of the examples I tried (without luck) today so I guess there is something wrong with my environment but I don't know how to debug it. 我之前已经运行了我的环境,我确信如果不是这个特定的例子,我已经能够运行容器并使用我尝试的一些示例(没有运气)连接到数据库,所以我猜有些问题与我的环境,但我不知道如何调试它。

I've removed all containers, all images, re-donwloaded the images and rebuilt de containers. 我删除了所有容器,所有图像,重新下载了图像并重建了容器。 Even tested everyithing on a enpty folder with a newly created docker-compose.yml file. 甚至在一个带有新创建的docker-compose.yml文件的enpty文件夹上进行测试。

In fact as reading the logs it seemed that maybe the wordpress process was exhausting its tries I have even restarted the wordpress container while the database container was already up and the result is the same. 事实上,当阅读日志时,似乎wordpress进程耗尽其尝试我甚至重新启动wordpress容器, 数据库容器已经启动且结果相同。

Just in case it's relevant I'm running all of this locally on a mac using the docker quickstart terminal as descrived here: 以防它是相关的我使用docker quickstart终端在mac上本地运行所有这些,如下所述:

https://docs.docker.com/mac/step_one/ https://docs.docker.com/mac/step_one/

and docker -v says: 码头工人-v说:

Docker version 1.9.1, build a34a1d5

EDIT: Just tried using: 编辑:刚试过使用:

image: wordpress:4.4

instead of "no tag" which downloads latest (4.4.1 at the time of writing) and it works. 而不是下载最新的“无标签”(在撰写本文时为4.4.1)并且它有效。 So it seems that is a bug introduced on 4.4.1 所以似乎这是4.4.1中引入的错误

I've oppened one here 我在这里打了一个

https://github.com/docker-library/wordpress/issues/120 https://github.com/docker-library/wordpress/issues/120

I'll keep the question open just in case but it seems quite clear that is a bug 我会保持问题公开以防万一,但似乎很明显这是一个错误

It was a bug on the version 4.4.1 of the wordpress container. 这是wordpress容器版本4.4.1的一个错误。

I've oppened an issue here https://github.com/docker-library/wordpress/issues/120 and it's solved now. 我在这里解决了一个问题https://github.com/docker-library/wordpress/issues/120现在已经解决了。

Thanks all! 谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM