Remove a context. Similar to the ``docker context rm`` command. Args: name (str): The name of the context Raises: :py:class:`docker.errors.MissingContextParameter` If a context name is not provided. :py:class:`docker.errors.Contex
(cls, name)
| 145 | |
| 146 | @classmethod |
| 147 | def remove_context(cls, name): |
| 148 | """Remove a context. Similar to the ``docker context rm`` command. |
| 149 | |
| 150 | Args: |
| 151 | name (str): The name of the context |
| 152 | |
| 153 | Raises: |
| 154 | :py:class:`docker.errors.MissingContextParameter` |
| 155 | If a context name is not provided. |
| 156 | :py:class:`docker.errors.ContextNotFound` |
| 157 | If a context with the name does not exist. |
| 158 | :py:class:`docker.errors.ContextException` |
| 159 | If name is default. |
| 160 | |
| 161 | Example: |
| 162 | |
| 163 | >>> from docker.context import ContextAPI |
| 164 | >>> ContextAPI.remove_context(name='test') |
| 165 | >>> |
| 166 | """ |
| 167 | if not name: |
| 168 | raise errors.MissingContextParameter("name") |
| 169 | if name == "default": |
| 170 | raise errors.ContextException( |
| 171 | 'context "default" cannot be removed') |
| 172 | ctx = Context.load_context(name) |
| 173 | if not ctx: |
| 174 | raise errors.ContextNotFound(name) |
| 175 | if name == get_current_context_name(): |
| 176 | write_context_name_to_docker_config(None) |
| 177 | ctx.remove() |
| 178 | |
| 179 | @classmethod |
| 180 | def inspect_context(cls, name="default"): |