testcontainers / testcontainers/testcontainers-python
Bug: Failure to connect to Reaper leaves stale ryuk containers, leading to container name collisions
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 2.3k
- 派生
- 386
- 平均合并
- 4 小时 40 分钟
- 30 天内合并 PR
- 1
描述
Describe the bug
Running testcontainers in a network-isolated environment leaves stale ryuk containers. Further down this produces misleading error messages about duplicate containers.
Reaper._create_instancestarts a new ryuk containerReaper._create_instancefails to connect to the reaper container.
Line 372s.connect((container_host, container_port))raisesConnectionRefusedError: [Errno 111] Connection refusedReaper._create_instanceleaves the container running, without assigning it toReaper._instance- Test fails with
Connection refusederror message above - Next test starts
Reaper._create_instanceattempts starting a new ryuk container. Fails with misleading error message:requests.exceptions.HTTPError: 409 Client Error: Conflict for url: http+docker://localhost/v1.55/containers/create?name=testcontainers-ryuk-6810abc7-a781-44ec-928a-2c671c8881d9. Normally this should reuse theReaper._instancebut since it was never assigned it will not realize that it is already running. The unique ID is only generated once per session.- Second test fails with the misleading message about duplicate ryuk containers.
To Reproduce
Run a pytest suite having at least 2 tests attempting to use testcontainers in a network-isolated environment, such as Bazel with tags=["block-network"]
BUILD.bazel
load("@rules_python//python:defs.bzl", "py_test")
py_test(
name = "test_ryuk_repro",
srcs = ["test_ryuk_repro.py"],
tags = ["block-network"],
deps = [
"@pip//pytest:pkg",
"@pip//testcontainers:pkg",
],
)
test_ryuk_repro.py
import pytest
from testcontainers.core.container import DockerContainer
def test_a():
with DockerContainer("hello-world"): # Fails with ConnectionError
pass
def test_b():
with DockerContainer("hello-world"): # Fails with 409 Conflict error
pass
Runtime environment
Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.
# Get the operating system information (on a unix os).
$ uname -a
Linux ... 7.0.0-27-generic #27-Ubuntu SMP PREEMPT_DYNAMIC Thu Jun 18 19:13:49 UTC 2026 x86_64 GNU/Linux
# Get the python version.
$ python --version
3.11
$ docker info
Client: Docker Engine - Community
Version: 29.6.1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.35.0
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v5.3.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
$ pip freeze
testcontainers==4.14.2
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Reaper._create_instance 开始,重点检查第 372 行的连接,并在网络隔离的环境中使用包含两个测试的 pytest 示例重现该失败。跟踪连接被拒绝时发生的情况,并验证后续测试不会遇到陈旧的 ryuk 容器或误导性的 409 名称冲突错误。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- docker, python
- 领域
- testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 72/100