runconfig/errors: split ErrConflictHostNetwork

Split the `ErrConflictHostNetwork` error into two distinct errors:

1. `ErrConflictConnectToHostNetwork` when attempting to change the
   network mode of a running container from a different mode to `host`
2. `ErrConflictDisconnectFromHostNetwork` when the network mode of a
   running container is `host` and attempting to disconnect from `host`

This commit clarifies error messaging by differentiating between the two
errors, making it clearer which operation failed and how to fix it.

Signed-off-by: Brendon Smith <bws@bws.bio>
This commit is contained in:
Brendon Smith
2025-03-08 17:13:20 -05:00
parent b4bdf12dae
commit 90a83063ee
3 changed files with 8 additions and 6 deletions

View File

@@ -173,7 +173,7 @@ func (daemon *Daemon) updateNetworkSettings(ctr *container.Container, n *libnetw
}
if !ctr.HostConfig.NetworkMode.IsHost() && containertypes.NetworkMode(n.Type()).IsHost() {
return runconfig.ErrConflictHostNetwork
return runconfig.ErrConflictConnectToHostNetwork
}
for s, v := range ctr.NetworkSettings.Networks {
@@ -1053,7 +1053,7 @@ func (daemon *Daemon) DisconnectFromNetwork(ctx context.Context, ctr *container.
delete(ctr.NetworkSettings.Networks, networkName)
} else if err == nil {
if ctr.HostConfig.NetworkMode.IsHost() && containertypes.NetworkMode(n.Type()).IsHost() {
return runconfig.ErrConflictHostNetwork
return runconfig.ErrConflictDisconnectFromHostNetwork
}
if err := daemon.disconnectFromNetwork(ctx, ctr, n, false); err != nil {