Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple networks #523

Open
martin-mueller-cemas opened this issue Dec 16, 2024 · 1 comment
Open

Allow multiple networks #523

martin-mueller-cemas opened this issue Dec 16, 2024 · 1 comment

Comments

@martin-mueller-cemas
Copy link

Proposed change

Allow spawned containes to be in multiple networks instead of only one.

Currently, DockerSpawner.network_name only allows to specify one network the container will be part of.

Alternative options

Instead of adding the container to multiple networks, the container can be added to the Docker default bridge (default setting for DockerSpawner.network_name. This way the container can communicate with other containers on the default bridge network, but only via IP addresses instead of host/service names.

Who would use this feature?

With the ability to set multiple networks, the containers do not need to be in the Docker default bridge and can access each other via host/service names. This also provides better network isolation and thus better security.

(Optional): Suggest a solution

DockerSpawner.network_name should be a list (like DockerSpawner.mounts) of all Docker networks the spawned container will be added.

@martin-mueller-cemas
Copy link
Author

I've found a workaround by subclassing the DockerSpawner class and overriding its start_object() in the JuypterHub configuration file:

from dockerspawner import DockerSpawner

class CustomDockerSpawner(DockerSpawner):
    async def start_object(self):
        await super().start_object()

        await self.docker(
            "connect_container_to_network",
            self.object_name,
            "network_name"
        )

c.JupyterHub.spawner_class = CustomDockerSpawner

Replace network_name with the Docker network name (or read it from the environment via os.getenv()).

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

No branches or pull requests

1 participant