我试图设置一些集成测试与docker撰写。我使用docker撰写来启动postgres数据库和nodejs服务器。然后我使用jest对服务器运行http请求。
由于某些原因,我不能解释所有的SQL查询(即使是最简单的)都非常慢(+ 1秒)。
这听起来像是两个容器之间的通信问题,但我不能发现它。我做错了什么吗?
这是我的docker-compose.yml
文件。服务器只是一个简单的express应用
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)
通过更改以下内容,尝试使用Volume而不是Bind Mount来创建数据文件夹:
- ./db-data:/var/lib/postgresql/data
:
- db-data:/var/lib/postgresql/data
并将此部分添加到撰写文件的末尾:
volumes:
db-data:
你可以在这里阅读更多关于绑定挂载和卷的信息
我找到了。问题不在于docker,而在于编译器。我正在使用ncc,它破坏了我的postgres客户端。
我在他们的repo中用一个最小可复制的例子打开了一个问题
https://github.com/vercel/ncc/issues/646
谢谢你的帮助