docker-compose wordpress mysql 连接被拒绝 [英] docker-compose wordpress mysql connection refused
问题描述
我创建了一个小的 docker-compose.yml
,它曾经像魅力一样工作,用于部署小型 WordPress 实例.它看起来像这样:
I've created a small docker-compose.yml
which used to work like a charm to deploy small WordPress instances. It looks like this:
wordpress:
image: wordpress:latest
links:
- mysql
ports:
- "1234:80"
environment:
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD: "password"
WORDPRESS_DB_HOST: mariadb
MYSQL_PORT_3306_TCP: 3306
volumes:
- /srv/wordpress/:/var/www/html/
mysql:
image: mariadb:latest
mem_limit: 256m
container_name: mariadb
environment:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: "password"
volumes:
- /srv/mariadb:/var/lib/mysql
但是当我现在启动它时(也许因为 docker 更新到 Docker 版本 1.9.1,构建 a34a1d5
),它失败了
But when I start it now (maybe since docker update to Docker version 1.9.1, build a34a1d5
), it fails
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
当我看到 wordpress_1
的 /etc/hosts
时,有 MySQL 的条目:
When I cat /etc/hosts
of the wordpress_1
there are entries for MySQL:
172.17.0.10 mysql 12a564fdbc56 mariadb
并且我能够 ping 通 MariaDB 服务器.
and I am able to ping the MariaDB server.
当我 docker-compose up
时,WordPress 被安装,并在多次重启后 MariaDB 容器打印:
When I docker-compose up
, WordPress gets installed and after several restarts the MariaDB container prints:
Version: '10.0.22-MariaDB-1~jessie' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
哪个应该表明它正在运行,不是吗?
Which schould indicate it to be running, isn't it?
如何让 WordPress 能够连接到 MariaDB 容器?
How do I get the WordPress to be able to connect to the MariaDB container?
推荐答案
这种行为的原因可能与最近的内核和 docker 更新有关.我在其他 docker-compose 设置中发现了其他几个连接问题.因此,我重新启动了服务器(不仅仅是 docker 服务)并且从那时起就没有出现任何类似的问题.
The reason for this behaviour probably was related to a recent kernel and docker update. I recognized several other connection issues in other docker-compose setups. Therefore I restarted the server (not just the docker service) and didn't have had any issues like this ever since.
这篇关于docker-compose wordpress mysql 连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!