docker-compose wordpress mysql连接被拒绝 [英] docker-compose wordpress mysql connection refused

查看:348
本文介绍了docker-compose wordpress mysql连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆