Add 'docker network edit' command for updating network labels#6851
Open
atoniolo76 wants to merge 1 commit intodocker:masterfrom
Open
Add 'docker network edit' command for updating network labels#6851atoniolo76 wants to merge 1 commit intodocker:masterfrom
atoniolo76 wants to merge 1 commit intodocker:masterfrom
Conversation
Adds a new 'docker network edit' subcommand that allows users to add or remove labels on an existing network using --label-add and --label-rm flags, consistent with the UX of 'docker service update'. Because the Docker Engine API does not expose a network-update endpoint, this command implements the change by inspecting the network, removing it, and recreating it with identical configuration and updated labels. To avoid disrupting connectivity the command refuses to operate on networks that have active endpoints, instructing the user to disconnect containers first. Signed-off-by: Alessio Toniolo <atoniolo76@gmail.com>
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.
What
Adds a new `docker network edit` subcommand that allows updating the labels of an existing network:
```
docker network edit [OPTIONS] NETWORK
Options:
--label-add key=value Add or update a label
--label-rm key Remove a label by key
```
Example:
```bash
Add labels
docker network edit --label-add env=prod --label-add team=platform mynet
Remove a label
docker network edit --label-rm env mynet
```
Why
There is currently no way to update a network after creation without deleting and manually recreating it. Labels are a common mechanism for organizing and filtering resources (e.g. for monitoring, cost attribution, or tooling), and users need to be able to update them without tearing down the network.
The new command follows the same `--label-add` / `--label-rm` UX as `docker service update`, making it consistent with the rest of the CLI.
How
Because the Docker Engine API does not expose a `PATCH /networks/{id}` endpoint, this command implements the change client-side:
Steps 3–4 are a narrow window where the network is absent; by requiring zero active endpoints beforehand, no running container loses connectivity.
Testing
Unit tests are added in `edit_test.go` covering:
Limitations / Future work