I am trying to run the docker-compose command on Jenkins slave but it fails while running the command pytest tests/integration. The command run integration tests with backend as postgres. Dockerfile is
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
And the error I am getting is
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?
I tried exposing port 5432 in docker-compose file in postgres_db section but didn't help. The same code works fine locally. The command I run is
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'this worked for me