testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Feature: A way to construct a `Network` object for an existing docker network

Open rhoban13 opened this issue 7 months ago • 0 comments

What are you trying to do?

Attach a DockerContainer to an existing network. In my specific case, the network was created as part of a composable setup, and I'd like to attach a new container to that network.

Why should it be done this way?

I suppose my suggestion would be a way to construct a Network object by simply passing the name in as an argument. Best I can tell that name property is all that is really needed when the DockerContainer is started.

A perhaps easier way might be to create a new class

class ExistingNetwork:
    def __init__(self, network_name: str):
        self.name = network_name

While this I think could be passed into DockerContainer.with_network & it seems to work, it might be better to have this inherit Network and explicitly override the other methods in the Network class to ensure they are not called.

rhoban13 avatar May 21 '25 20:05 rhoban13