-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Desired Behavior
I need a docker network rm --force command that exits with success if the specified network doesn't exist. This analogous to the rm -f shell command.
$ docker network rm --force nonexistent_network ; echo $?
0
Current Behavior
Currently, the command exits with status 1 if no networks were deleted.
$ docker network rm nonexistent_network ; echo $?
Error: No such network: nonexistent_network
1
Why I need this change
I am calling this command in a cleanup script. I need to be able to run the script repeatedly, without creating any networks in between runs. The script needs to stop and report an error if docker network rm cannot do what it needs to do. For example, if it cannot connect to dockerd. But if the networks are already deleted, then the script needs to continue. With the current behavior of docker network rm, the script must perform its own check for networks before calling docker network rm . This is extra code. Alternatively, the script can silently ignore failure of the command. This has serious drawbacks.