我创建了一个小工具docker-compose.yml,过去它像一个魅力一样可以部署小型WordPress实例。看起来像这样:
docker-compose.yml
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版本,build a34a1d5),它失败了
a34a1d5
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10 wordpress_1 | wordpress_1 | MySQL Connection Error: (2002) Connection refused
当我的猫/etc/hosts的wordpress_1有项针对MySQL:
/etc/hosts
wordpress_1
172.17.0.10 mysql 12a564fdbc56 mariadb
而且我能够ping通MariaDB服务器。
当我docker-compose up安装WordPress并多次重启后,MariaDB容器打印出来:
docker-compose up
Version: '10.0.22-MariaDB-1~jessie' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
是哪个指示它正在运行,不是吗?
我如何获得WordPress才能连接到MariaDB容器?
出现这种现象的原因可能与最近的内核和docker更新有关。我在其他docker- compose设置中认识到其他几个连接问题。因此,我重新启动了服务器(不仅仅是docker服务),此后再也没有出现过这样的问题。