【问题标题】:Weird interference between two DDEV projects using PostgreSQL使用 PostgreSQL 的两个 DDEV 项目之间的奇怪干扰
【发布时间】:2021-11-12 13:40:21
【问题描述】:

我正在开发两个使用 PostgreSQL(基于 procedure described here)的 Drupal(7 和 9)项目。当它们同时运行时我注意到错误:Drupal 7 会抱怨variable 表不存在,而 Drupal 9 会断开我的连接或显示某种 WSOD。奇怪的是,它们可以随机正常工作或在页面重新加载时再次崩溃。但是,当我关闭它时,它会变得非常好。

这一切让我想起我配置 PostgreSQL 的方式有些麻烦。你能帮我找出我的设置可能有什么问题吗?

这是我对 Drupal 9 的配置。docker-compose.postgres.yaml:

version: '3.6'
services:
  postgres:
    container_name: ddev-${DDEV_SITENAME}-postgres
    image: postgres:13.4
    ports:
      - 32784:5432
    environment:
      - POSTGRES_PASSWORD=<REDACTED>
      - POSTGRES_USER=<REDACTED>
      - POSTGRES_DB=<REDACTED>
    volumes:
      - type: "volume"
        source: postgres
        target: "/var/lib/postgresql/data"
        volume:
          nocopy: true
      - type: "bind"
        source: "."
        target: "/mnt/ddev_config"
      - ddev-global-cache:/mnt/ddev-global-cache
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
  web:
    links:
      - postgres:postgres

volumes:
  postgres:

还有settings.ddev.php:

<?php                                                      
                                                           
/**                                                                                                                    
 * @file                                                   
 * Manually managed.                                       
 */                                                        

$host = "postgres";                                        
$port = 5432;                                              

// If DDEV_PHP_VERSION is not set but IS_DDEV_PROJECT *is*, it means we're running (drush) on the host,
// so use the host-side bind port on docker IP
if (empty(getenv('DDEV_PHP_VERSION') && getenv('IS_DDEV_PROJECT') == 'true')) {
  $host = "127.0.0.1";                                     
  $port = -1;                                              
}                                                          

$databases['default']['default'] = array(
  'database' => "<REDACTED>",                                      
  'username' => "<REDACTED>",                                      
  'password' => "<REDACTED>",                                      
  'host' => $host,                                         
  'driver' => "pgsql",                                     
  'port' => $port,                                         
  'prefix' => "",                                          
);                                                         

(省略哈希和配置设置。)

现在,对于 Drupal 7。docker-compose.postgres.yaml:

version: '3.6'
services:
  postgres:
    container_name: ddev-${DDEV_SITENAME}-postgres
    image: mdillon/postgis:11
    ports:
      - 32785:5432
    environment:
      - POSTGRES_PASSWORD=<REDACTED>
      - POSTGRES_USER=<REDACTED>
      - POSTGRES_DB=<REDACTED>
    volumes:
      - type: "volume"
        source: postgres
        target: "/var/lib/postgresql/data"
        volume:
          nocopy: true
      - type: "bind"
        source: "."
        target: "/mnt/ddev_config"
      - ddev-global-cache:/mnt/ddev-global-cache
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
  web:
    links:
      - postgres:postgres

volumes:
  postgres:

settings.ddev.php:

<?php

/**
 * @file
 * Manually managed.
 */

$host = "postgres";
$port = 5432;

// If DDEV_PHP_VERSION is not set but IS_DDEV_PROJECT *is*, it means we're
// running (drush) on the host, so use the host-side bind port on docker IP.
if (empty(getenv('DDEV_PHP_VERSION') && getenv('IS_DDEV_PROJECT') == 'true')) {
  $host = "127.0.0.1";
  $port = 32784;
}

$databases['default']['default'] = [
  'database' => "<REDACTED>",
  'username' => "<REDACTED>",
  'password' => "<REDACTED>",
  'host' => $host,
  'driver' => "pgsql",
  'port' => $port,
  'prefix' => "",
];

我能够检查到 postgres 实际上是不同 FQDN 和不同 IP 的别名(不是很了解 Docker Compose,对此感到抱歉)。

我的系统上有两个不同的卷(尽管我不能保证它们被正确使用):

$ docker volume ls | grep postgres     
local     ddev-mgis_postgres
local     ddev-mgisv5_postgres

当我从 Drupal 7 项目运行 drush sqlc 时,我看到 Drupal 9 表,直到关闭另一个项目。真是一场噩梦!

我最大的担心是两个项目可能会共享资源,并可能在某个时候在同一个地方写作。

我需要能够同时运行两个项目,因为其中一个需要迁移到另一个。

【问题讨论】:

    标签: ddev


    【解决方案1】:

    DDEV v1.19+ 更新

    1. Postgres 现在随 DDEV 一起提供,因此无需额外的服务/容器。
    2. 您不再需要为容器使用明确的名称,因为 DDEV 中的网络现在更加复杂。

    ------下面的原始答案----------

    您正在使用$host = "postgres";,请使用postgres 容器的显式名称ddev-&lt;project&gt;-postgres

    当您运行多个具有名为“postgres”的服务的项目时,主机名postgres 在 docker 网络中不明确。所以你得到了你所看到的行为。

    ddev-contrib 配方的 PR 将不胜感激;自从大约一年前发现问题以来,许多 ddev-contrib 配方中都已对此进行了更新,但显然不是这个。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    • 2014-10-21
    • 2016-03-24
    • 2019-02-06
    相关资源
    最近更新 更多