【问题标题】:Docker services not linked - WordPress not connecting to MySQLDocker 服务未链接 - WordPress 未连接到 MySQL
【发布时间】:2019-06-14 04:55:29
【问题描述】:

这是我第一次使用 Docker。我有一个 WordPress 网站,我使用 https://phpdocker.io/ 生成了一些文件,包括 docker-compose.yml

我将包内容放在项目的根目录中,然后尝试运行 docker-compose up -d,我可以连接到我的 MySQL,在其中加载我的 SQL 转储,然后转到 http://localhost,但它说“连接可以” t 建立”,启用调试时我得到:

警告:mysqli_real_connect(): (HY000/2002): 第 1531 行的 /application/wp-includes/wp-db.php 中没有这样的文件或目录 建立数据库连接时出错

我添加了links,但这并没有帮助。这就是我的docker-compose.yml 的样子:

    ###############################################################################
#                          Generated on local                                 #
###############################################################################
version: "3.1"
services:

  redis:
    image: redis:alpine
    container_name: local-wordpress-redis

  mysql:
    image: mysql:5.7
    container_name: local-wordpress-mysql
    working_dir: /application
    volumes:
      - .:/application
    command: --max_allowed_packet=32505856
    environment:
      - MYSQL_ROOT_PASSWORD=mypass
      - MYSQL_DATABASE=local
      - MYSQL_USER=orbuser
      - MYSQL_PASSWORD=mypass
    ports:
      - "3306:3306"

  webserver:
    image: nginx:alpine
    container_name: local-wordpress-webserver
    working_dir: /application
    volumes:
      - .:/application
      - ./local/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "80:80"
    links:
      - mysql
      - redis

  php-fpm:
    build: local/php-fpm
    container_name: local-wordpress-php-fpm
    working_dir: /application
    volumes:
      - .:/application
      - ./local/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
    links:
      - mysql
      - redis

wp-config.php

<?php
define('WP_CACHE', true); // Added by W3 Total Cache

define('DB_NAME', 'local');
define('DB_USER', 'orbuser');
define('DB_PASSWORD', 'mypass');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');

define('AUTH_KEY',         'xx');
define('SECURE_AUTH_KEY',  'xx');
define('LOGGED_IN_KEY',    'xx');
define('AUTH_SALT',        'xx');
define('SECURE_AUTH_SALT', 'xx');
define('LOGGED_IN_SALT',   'xx');
define('NONCE_SALT',       'xx');

$table_prefix  = 'ftom_';

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);

if ( !defined('ABSPATH') )
    define('ABSPATH', '/');

require_once(ABSPATH . 'wp-settings.php');

【问题讨论】:

  • 你在 PHP 容器中的主机名是什么?
  • 我不知道。你能告诉我如何检查吗?
  • 请同时发布您的wp-config.php 文件的内容。
  • 可能类似于github.com/mjstealey/wordpress-nginx-docker 上的WORDPRESS_DB_NAME 设置
  • @cabrerahector 我按照您的要求添加了 wp-config.php。

标签: php mysql wordpress docker


【解决方案1】:

DB_HOST 应设置为容器名称:mysql。 目前您的 wordpress 正在自己的循环中寻找数据库。

【讨论】:

猜你喜欢
  • 2020-09-18
  • 1970-01-01
  • 2023-03-23
  • 2018-10-02
  • 2021-01-02
  • 1970-01-01
  • 2018-10-06
  • 2019-06-02
  • 2022-07-12
相关资源
最近更新 更多