Skip to content

Bug: HealthcheckWaitStrategy returns error with DockerCompose #905

@reyescabello

Description

@reyescabello

Describe the bug

When applying a 'waiting_for' to a DockerCompose object with a HealthcheckWaitStrategy, it returns an AttributeError: “ComposeContainer” object has no attribute “attrs”.

To Reproduce

import os
from testcontainers.compose import DockerCompose
from testcontainers.core.wait_strategies import HealthcheckWaitStrategy

BASE_DIR = os.path.dirname(__file__)

compose = DockerCompose(context=BASE_DIR, compose_file_name = "docker-compose.yml")
compose.waiting_for({"web": HealthcheckWaitStrategy().with_startup_timeout(60)})
compose.start()

docker-compose.yml:

version: '3.8'
services:
  web:
    image: nginx
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Traceback:

Traceback (most recent call last):
  File "<path>/test.py", line 9, in <module>
    compose.start()
  File "testcontainers/compose/compose.py", line 303, in start
    strategy.wait_until_ready(container)
  File "testcontainers/core/wait_strategies.py", line 487, in wait_until_ready
    health = wrapped.attrs.get("State", {}).get("Health", {})
             ^^^^^^^^^^^^^
AttributeError: 'ComposeContainer' object has no attribute 'attrs'

Runtime environment

$ uname -a
Linux kali 6.8.0-85-generic #85-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 18 15:26:59 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 3.12.1
$ poetry show | grep testcontainers
testcontainers                                  4.13.2 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions