GeezerVison is showing github.com — Bug: `K3SContainer` does not support other connection modes (in `get_container_host_ip`) · Issue #861 · testcontainers/testcontainers-python
Bug: K3SContainer does not support other connection modes (in get_container_host_ip) #861DescriptionDescribe the bug
K3SContainer calls get_container_host_ip in its __init__ method here and here before the container is started, causing it to fail with an AssertionError here.
To Reproduce
from testcontainers.k3s import K3SContainer
with K3SContainer() as k3s:
print("gonna throw an error before I even get here :(")
Runtime environment
I'm on an ARM Mac and this is in Python 3.12, but that shouldn't make a difference. Activityalexanderankin commented on Aug 13, 2025 If there is a bug, it was probably introduced with the new waiting
strategies, thanks for reporting, I'll take a look
…alexanderankin commented on Aug 13, 2025 oh, seems like we have to re-think container modes - or k3s - the new
container modes that try to help address dind/dood are not compatible with
the k3s container. ill move the assert inside the if branches that need it,
and then it will work by default (not dind or dood or whatever0
…
On Wed, Aug 13, 2025 at 6:07 PM David Ankin ***@***.***> wrote:
If there is a bug, it was probably introduced with the new waiting
strategies, thanks for reporting, I'll take a look
On Wed, Aug 13, 2025, 5:19 PM ndellosa95 ***@***.***> wrote:
> *ndellosa95* created an issue ( testcontainers/testcontainers-python#861)
> < #861>
>
> *Describe the bug*
>
> K3SContainer calls get_container_host_ip in its __init__ method here and
> here
> < https://github.com/testcontainers/testcontainers-python/blob/main/modules/k3s/testcontainers/k3s/__init__.py#L45-L46>
> before the container is started, causing it to fail with an
> AssertionError here
> < https://github.com/testcontainers/testcontainers-python/blame/main/core/testcontainers/core/container.py#L229-L231>
> .
>
> *To Reproduce*
>
> from testcontainers.k3s import K3SContainer
> with K3SContainer() as k3s:
> print("gonna throw an error before I even get here :(")
>
> *Runtime environment*
>
> I'm on an ARM Mac and this is in Python 3.12, but that shouldn't make a
> difference.
>
> —
> Reply to this email directly, view it on GitHub
> < #861>, or
> unsubscribe
> < https://github.com/notifications/unsubscribe-auth/ACECGJGKK2FYZLF55ITU6ML3NOTVJAVCNFSM6AAAAACD23I4WKVHI2DSMVQWIX3LMV43ASLTON2WKOZTGMYTSOJTGA3TQNY>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
alexanderankin commented on Aug 14, 2025 marbon87 commented on Sep 11, 2025 Still having the same error with 4.13.0:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.12/site-packages/testcontainers/k3s/__init__.py:45: in __init__
self.with_env("K3S_URL", f"https://{self.get_container_host_ip()}:{self.KUBE_SECURE_PORT}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <testcontainers.k3s.K3SContainer object at 0x7f087cac1250>
def get_container_host_ip(self) -> str:
connection_mode: ConnectionMode
connection_mode = self.get_docker_client().get_connection_mode()
if connection_mode == ConnectionMode.docker_host:
return self.get_docker_client().host()
elif connection_mode == ConnectionMode.gateway_ip:
# mypy:
container = self._container
> assert container is not None
^^^^^^^^^^^^^^^^^^^^^
E AssertionError
alexanderankin commented on Sep 11, 2025 the fact that k3scontainer does not support other connection modes is not an issue with the core library, thats an issue with the community module. PR's welcome. before we introduced this change, this should have never worked with dind in the first place - connection modes allow for use of gateway_ip specifically. so in this case you can set the connection mode to docker_host and see if that works, otherwise we have to think together about how to solve this - getting the container's private ip before it exists - dont think this is possible. I believe the earlier behavior was just using connection mode = docker host changed the title [-]Bug: `K3SContainer` calls `get_container_host_ip` in constructor before container is started[/-] [+]Bug: `K3SContainer` does not support DinD (in `get_container_host_ip`)[/+] on Sep 11, 2025changed the title [-]Bug: `K3SContainer` does not support DinD (in `get_container_host_ip`)[/-] [+]Bug: `K3SContainer` does not support other connection modes (in `get_container_host_ip`)[/+] on Sep 11, 2025marbon87 commented on Sep 12, 2025 Hi @alexanderankin ,
setting the conncetion-mode to docker_host with
os.environ["TESTCONTAINERS_CONNECTION_MODE"] = "docker_host"
from testcontainers.k3s import K3SContainer
does solve the problem.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|