contrib: make dockerd-rootless-setuptool.sh more robust#44213
Merged
thaJeztah merged 1 commit intomoby:masterfrom Sep 29, 2022
Merged
contrib: make dockerd-rootless-setuptool.sh more robust#44213thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah merged 1 commit intomoby:masterfrom
Conversation
The `docker` CLI currently doesn't handle situations where the current context
(as defined in `~/.docker/config.json`) is invalid or doesn't exist. As loading
(and checking) the context happens during initialization of the CLI, this
prevents `docker context` commands from being used, which makes it complicated
to fix the situation. For example, running `docker context use <correct context>`
would fail, which makes it not possible to update the `~/.docker/config.json`,
unless doing so manually.
For example, given the following `~/.docker/config.json`:
```json
{
"currentContext": "nosuchcontext"
}
```
All of the commands below fail:
```bash
docker context inspect rootless
Current context "nosuchcontext" is not found on the file system, please check your config file at /Users/thajeztah/.docker/config.json
docker context rm --force rootless
Current context "nosuchcontext" is not found on the file system, please check your config file at /Users/thajeztah/.docker/config.json
docker context use default
Current context "nosuchcontext" is not found on the file system, please check your config file at /Users/thajeztah/.docker/config.json
```
While these things should be fixed, this patch updates the script to switch
the context using the `--context` flag; this flag is taken into account when
initializing the CLI, so that having an invalid context configured won't
block `docker context` commands from being executed. Given that all `context`
commands are local operations, "any" context can be used (it doesn't need to
make a connection with the daemon).
With this patch, those commands can now be run (and won't fail for the wrong
reason);
```bash
docker --context=default context inspect -f "{{.Name}}" rootless
rootless
docker --context=default context inspect -f "{{.Name}}" rootless-doesnt-exist
context "rootless-doesnt-exist" does not exist
```
One other issue may also cause things to fail during uninstall; trying to remove
a context that doesn't exist will fail (even with the `-f` / `--force` option
set);
```bash
docker --context=default context rm blablabla
Error: context "blablabla": not found
```
While this is "ok" in most circumstances, it also means that (potentially) the
current context is not reset to "default", so this patch adds an explicit
`docker context use`, as well as unsetting the `DOCKER_HOST` and `DOCKER_CONTEXT`
environment variables.
Signed-off-by: Sebastiaan van Stijn <[email protected]>
AkihiroSuda
approved these changes
Sep 28, 2022
This was referenced Sep 29, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
dockerCLI currently doesn't handle situations where the current context (as defined in~/.docker/config.json) is invalid or doesn't exist. As loading (and checking) the context happens during initialization of the CLI, this preventsdocker contextcommands from being used, which makes it complicated to fix the situation. For example, runningdocker context use <correct context>would fail, which makes it not possible to update the~/.docker/config.json, unless doing so manually.For example, given the following
~/.docker/config.json:{ "currentContext": "nosuchcontext" }All of the commands below fail:
While these things should be fixed, this patch updates the script to switch the context using the
--contextflag; this flag is taken into account when initializing the CLI, so that having an invalid context configured won't blockdocker contextcommands from being executed. Given that allcontextcommands are local operations, "any" context can be used (it doesn't need to make a connection with the daemon).With this patch, those commands can now be run (and won't fail for the wrong reason);
One other issue may also cause things to fail during uninstall; trying to remove a context that doesn't exist will fail (even with the
-f/--forceoption set);docker --context=default context rm blablabla Error: context "blablabla": not foundWhile this is "ok" in most circumstances, it also means that (potentially) the current context is not reset to "default", so this patch adds an explicit
docker context use, as well as unsetting theDOCKER_HOSTandDOCKER_CONTEXTenvironment variables.- A picture of a cute animal (not mandatory but encouraged)