【发布时间】:2021-01-25 16:00:07
【问题描述】:
我正在尝试使用 docker compose 设置一些集成测试。我正在使用 docker compose 来启动 postgres 数据库和 nodejs 服务器。然后我使用 jest 对服务器运行 http 请求。
由于某些原因,我无法解释所有 SQL 查询(即使是最简单的查询)都非常慢(+ 1 秒)。
这听起来像是两个容器之间的通信问题,但我无法发现它。我是不是做错了什么?
这是我的docker-compose.yml 文件。服务器只是一个简单的快递应用
version: "3.9"
services:
database:
image: postgres:12
env_file: .env
volumes:
- ./db-data:/var/lib/postgresql/data
healthcheck:
test: pg_isready -U test_user -d test_database
interval: 1s
timeout: 10s
retries: 3
start_period: 0s
server:
build: .
ports:
- "8080:8080"
depends_on:
database:
condition: service_healthy
env_file: .env
environment:
POSTGRES_HOST: database
NODE_ENV: test
init: true
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/healthcheck"]
interval: 1s
timeout: 10s
retries: 3
start_period: 0s
编辑 我正在使用
Docker version 20.10.2, build 2291f61
macOs BigSur 11.1 (20C69)
【问题讨论】:
-
1.你能对不同版本的postgresql进行测试吗?例如。尝试 postgres:13 或 postgres:11 只是为了测试。 2.你提到node.js:它是哪个版本?我们遇到了 14 + postgresql 的问题。可以试试12吗? 3. 只有来自 node.js 或其他地方的查询才慢?
-
@AlexYu 我发现了这个问题,它不在 docker 中,而是在 postgres 客户端中。感谢您的帮助
标签: node.js postgresql docker