1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/contrib
Sebastiaan van Stijn fd0904805c
contrib: make dockerd-rootless-setuptool.sh more robust
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 <github@gone.nl>
(cherry picked from commit e2114731e7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-29 10:03:30 +02:00
..
apparmor AppArmor: add missing rules for running in userns 2019-09-30 16:17:13 +02:00
busybox ci(windows): move windows-2019 to another workflow 2022-08-31 11:57:23 +02:00
docker-device-tool Finish refactor of UID/GID usage to a new struct 2022-03-14 16:28:57 -04:00
gitdm run shfmt 2020-03-03 12:27:49 +09:00
httpserver linting: gosec: fix or suppress G112, G114 in test code 2022-09-06 15:11:42 +02:00
init fix debian sysvinit script fails to restart docker daemon when stopped 2022-09-21 16:32:57 +02:00
nnp-test Dockerfile: frozen images: update to bullseye, remove buildpack-dep 2021-08-20 18:23:06 +02:00
syntax Remove vim syntax files 2020-01-14 13:01:18 -04:00
syscall-test Dockerfile: frozen images: update to bullseye, remove buildpack-dep 2021-08-20 18:23:06 +02:00
udev
check-config.sh fix(check-config.sh): Check for existence of /etc/os-release before sourcing 2022-02-11 11:40:32 -07:00
dockerd-rootless-setuptool.sh contrib: make dockerd-rootless-setuptool.sh more robust 2022-09-29 10:03:30 +02:00
dockerd-rootless.sh Improved readability of the run hack script 2022-05-10 11:57:39 +02:00
dockerize-disk.sh run shfmt 2020-03-03 12:27:49 +09:00
download-frozen-image-v2.sh all: fix typos 2022-03-01 14:26:35 +08:00
editorconfig
mac-install-bundle.sh run shfmt 2020-03-03 12:27:49 +09:00
mkimage-alpine.sh run shfmt 2020-03-03 12:27:49 +09:00
mkimage-arch-pacman.conf
mkimage-arch.sh run shfmt 2020-03-03 12:27:49 +09:00
mkimage-archarm-pacman.conf
mkimage-crux.sh run shfmt 2020-03-03 12:27:49 +09:00
mkimage-pld.sh
mkimage-yum.sh all: fix typos 2022-03-01 14:26:35 +08:00
nuke-graph-directory.sh Update contrib/nuke-graph-directory.sh 2021-04-09 10:05:35 +10:00
README.md

The contrib directory contains scripts, images, and other helpful things which are not part of the core docker distribution. Please note that they could be out of date, since they do not receive the same attention as the rest of the repository.