【发布时间】: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