github.com/tonistiigi/docker@v0.10.1-0.20240229224939-974013b0dc6a/api/types/container/hostconfig_unix.go (about)

     1  //go:build !windows
     2  
     3  package container // import "github.com/docker/docker/api/types/container"
     4  
     5  import "github.com/docker/docker/api/types/network"
     6  
     7  // IsValid indicates if an isolation technology is valid
     8  func (i Isolation) IsValid() bool {
     9  	return i.IsDefault()
    10  }
    11  
    12  // NetworkName returns the name of the network stack.
    13  func (n NetworkMode) NetworkName() string {
    14  	if n.IsBridge() {
    15  		return network.NetworkBridge
    16  	} else if n.IsHost() {
    17  		return network.NetworkHost
    18  	} else if n.IsContainer() {
    19  		return "container"
    20  	} else if n.IsNone() {
    21  		return network.NetworkNone
    22  	} else if n.IsDefault() {
    23  		return network.NetworkDefault
    24  	} else if n.IsUserDefined() {
    25  		return n.UserDefined()
    26  	}
    27  	return ""
    28  }
    29  
    30  // IsBridge indicates whether container uses the bridge network stack
    31  func (n NetworkMode) IsBridge() bool {
    32  	return n == network.NetworkBridge
    33  }
    34  
    35  // IsHost indicates whether container uses the host network stack.
    36  func (n NetworkMode) IsHost() bool {
    37  	return n == network.NetworkHost
    38  }
    39  
    40  // IsUserDefined indicates user-created network
    41  func (n NetworkMode) IsUserDefined() bool {
    42  	return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer()
    43  }