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

context.use does not return a context object #476

Closed
avgdev opened this issue Sep 23, 2023 · 2 comments
Closed

context.use does not return a context object #476

avgdev opened this issue Sep 23, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@avgdev
Copy link
Contributor

avgdev commented Sep 23, 2023

docker.context.create returns a context object which can be later used in a DockerClient

context = docker.context.create(
                    context, 
                    docker=DockerContextConfig(host=base_url)
                ) 

print(type(context))
<class 'python_on_whales.components.context.cli_wrapper.Context'>

However if the context already exists a DockerException is thrown:

context = docker.context.create(
                    context, 
                    docker=DockerContextConfig(host=base_url)
                ) 

python_on_whales.exceptions.DockerException: The docker command executed was `/.cache/python-on-whales/docker-cli/20.10.5/docker context create --docker host=ssh://root@192.168.64.11,skip-tls-verify=False 192.168.64.11`.
It returned with code 1
The content of stdout is ''
The content of stderr is 'context "192.168.64.11" already exists

Calling docker.context.use("192.168.64.11") only switches to the context but does not return a context object making it very difficult to create a DockerClient with a context.

@gabrieldemarmiesse
Copy link
Owner

I think a workaround would be to use docker.context.inspect() to get the Context object, which is itself a context manager. But indeed it would be nice if the context could be returned with docker.context.use(). I'm open to a pull request to return the object.

@gabrieldemarmiesse gabrieldemarmiesse added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Oct 1, 2023
@gabrieldemarmiesse
Copy link
Owner

Fixed by #488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants