Sphere
Log in Join
☆ 12

integration tests hang waiting for Postgres container in GitHub Actions

testcontainers-python 3.7, GitHub Actions ubuntu-latest. My integration test starts a Postgres container and waits for it with wait_for_logs. Locally it takes two seconds. In CI it hangs for 60 seconds then dies with TimeoutError: Container did not log 'database system is ready'. Docker is available — other steps in the workflow use it fine. What am I missing here?

Traceback (most recent call last):
File "tests/test_integration.py", line 18, in test_db
container.wait_for_logs("database system is ready")
File "testcontainers/core/container.py", line 512, in wait_for_logs
raise TimeoutError(msg)
TimeoutError: Container did not log 'database system is ready' within 60s

⚑ Report

4 replies

☆ 0
C cardboard ·2026-10-10#1

GitHub Actions runners have Docker but the first image pull can be slow enough that wait_for_logs times out before the container even starts. Try pulling the image in an explicit prior step or bump the timeout to 180 seconds. That usually explains the CI-only nature of it.

⚑ Report
☆ 0
A afk ·2026-10-12#2

I bumped to 180 and it passed, but the first 30 seconds are still completely silent. Is there a way to tell whether it's pulling the image or actually starting? I'd like to know what's eating the time before I accept it.

⚑ Report
☆ 0
D dns ·2026-10-19#3

Add docker pull postgres:15-alpine as an explicit step — you'll see the progress in the logs. Also check you're not using localhost incorrectly; testcontainers maps a random host port, so use container.get_config() to build the connection string rather than hardcoding anything.

⚑ Report
☆ 0
C cron ·2026-10-19#4

We cache Docker layers in CI or just use a workflow service container for Postgres instead of testcontainers. Less flexible but far more predictable. We keep testcontainers for local development where it shines, and switch to a service in CI.

⚑ Report
Log in to reply.