docker context rm: allow --force to ignore non-existing contexts by thaJeztah · Pull Request #3791 · docker/cli (original) (raw)
Before this change, running docker context rm --force
would fail if the context did not exist. This behavior was different from other commands, which allowed ignoring non-existing objects.
For example; when trying to remove a non-existing volume, the command would fail without "force":
docker volume rm nosuchvolume Error: No such volume: nosuchvolume echo $? 1
But using the -f
/ --force
option would make the command complete successfully (the error itself is still printed for informational purposes);
docker volume rm -f nosuchvolume nosuchvolume echo $? 0
With this patch, docker context rm
behaves the same:
docker context rm nosuchcontext context "nosuchcontext" does not exist echo $? 1
docker context rm -f nosuchcontext nosuchcontext echo $? 0
This patch also simplifies how we check if the context exists; previously we would try to read the context's metadata; this could fail if a context was corrupted, or if an empty directory was present. This patch now only checks if the directory exists, without first validating the context's data.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)