GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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) #861

New issue
Copy link
New issue
Copy link
Open
Open
Bug: K3SContainer does not support other connection modes (in get_container_host_ip)#861
Copy link

Description

@ndellosa95
ndellosa95
opened on Aug 13, 2025
Issue body actions

Describe 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.

Activity

  1. alexanderankin commented on Aug 13, 2025

    @alexanderankin
    alexanderankin
    on Aug 13, 2025 via email
    Member
    More actions
    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: ***@***.***>
  2. alexanderankin commented on Aug 13, 2025

    @alexanderankin
    alexanderankin
    on Aug 13, 2025 via email
    Member
    More actions
    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: ***@***.***> >
  3. alexanderankin commented on Aug 14, 2025

    @alexanderankin
    alexanderankin
    on Aug 14, 2025
    Member
    More actions

    #862

  4. marbon87 commented on Sep 11, 2025

    @marbon87
    marbon87
    on Sep 11, 2025
    More actions

    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
    
  5. alexanderankin commented on Sep 11, 2025

    @alexanderankin
    alexanderankin
    on Sep 11, 2025
    Member
    More actions

    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

  6. alexanderankin
    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, 2025
  7. alexanderankin
    changed 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, 2025
  8. marbon87 commented on Sep 12, 2025

    @marbon87
    marbon87
    on Sep 12, 2025
    More actions

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.