【发布时间】:2021-08-02 10:16:18
【问题描述】:
我正在尝试在 Jenkins slave 上运行 docker-compose 命令,但在运行命令 pytest 测试/集成时失败。 该命令使用后端作为 postgres 运行集成测试。 Dockerfile 是
version: "3.4"
services:
test:
build:
context: ../..
dockerfile: Dockerfile
depends_on:
- postgres_db
environment:
PG_UNITTEST_DB: "postgresql://testuser:testpassword@postgres_db/testdb"
command: pytest tests/integration
postgres_db:
image: postgis/postgis
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: testpassword
POSTGRES_USER: testuser
POSTGRES_DB: testdb
我得到的错误是
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "postgres_db" (172.19.0.2) and accepting
TCP/IP connections on port 5432?
我尝试在 postgres_db 部分的 docker-compose 文件中公开端口 5432,但没有帮助。相同的代码在本地运行良好。我运行的命令是
docker-compose -f tests/integration/docker-compose.yml up --build --exit-code-from test
【问题讨论】:
-
command: bash -c 'while !</dev/tcp/postgres_db/5432; do sleep 1; done; pytest tests/integration'这对我有用
标签: docker docker-compose