{"modulePath":"github.com/docker/libnetwork","version":"v0.5.6","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package libnetwork\n\nPackage libnetwork provides the basic functionality and extension points to create network namespaces and allocate interfaces for containers to use.\n\n\tnetworkType := \"bridge\"\n\n\t// Create a new controller instance\n\tdriverOptions := options.Generic{}\n\tgenericOption := make(map[string]interface{})\n\tgenericOption[netlabel.GenericData] = driverOptions\n\tcontroller, err := libnetwork.New(config.OptionDriverConfig(networkType, genericOption))\n\tif err != nil {\n\t\treturn\n\t}\n\n\t// Create a network for containers to join.\n\t// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can make use of\n\tnetwork, err := controller.NewNetwork(networkType, \"network1\")\n\tif err != nil {\n\t\treturn\n\t}\n\n\t// For each new container: allocate IP and interfaces. The returned network\n\t// settings will be used for container infos (inspect and such), as well as\n\t// iptables rules for port publishing. This info is contained or accessible\n\t// from the returned endpoint.\n\tep, err := network.CreateEndpoint(\"Endpoint1\")\n\tif err != nil {\n\t\treturn\n\t}\n\n\t// Create the sandbox for the container.\n\t// NewSandbox accepts Variadic optional arguments which libnetwork can use.\n\tsbx, err := controller.NewSandbox(\"container1\",\n\t\tlibnetwork.OptionHostname(\"test\"),\n\t\tlibnetwork.OptionDomainname(\"docker.io\"))\n\n\t// A sandbox can join the endpoint via the join api.\n\terr = ep.Join(sbx)\n\tif err != nil {\n\t\treturn\n\t}\n\n## Functions\n\n```go\nfunc SetExternalKey(controllerID string, containerID string, key string) error\n```\nSetExternalKey provides a convenient way to set an External key to a sandbox\n\n## Types\n\n```go\ntype ActiveContainerError struct {\n\t// contains filtered or unexported fields\n}\n```\nActiveContainerError is returned when an endpoint is deleted which has active containers attached to it.\n\n```go\nfunc (ace *ActiveContainerError) Error() string\n```\n\n```go\nfunc (ace *ActiveContainerError) Forbidden()\n```\nForbidden denotes the type of this error\n\n```go\ntype ActiveEndpointsError struct {\n\t// contains filtered or unexported fields\n}\n```\nActiveEndpointsError is returned when a network is deleted which has active endpoints in it.\n\n```go\nfunc (aee *ActiveEndpointsError) Error() string\n```\n\n```go\nfunc (aee *ActiveEndpointsError) Forbidden()\n```\nForbidden denotes the type of this error\n\n```go\ntype Endpoint interface {\n\t// A system generated id for this endpoint.\n\tID() string\n\n\t// Name returns the name of this endpoint.\n\tName() string\n\n\t// Network returns the name of the network to which this endpoint is attached.\n\tNetwork() string\n\n\t// Join joins the sandbox to the endpoint and populates into the sandbox\n\t// the network resources allocated for the endpoint.\n\tJoin(sandbox Sandbox, options ...EndpointOption) error\n\n\t// Leave detaches the network resources populated in the sandbox.\n\tLeave(sandbox Sandbox, options ...EndpointOption) error\n\n\t// Return certain operational data belonging to this endpoint\n\tInfo() EndpointInfo\n\n\t// DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver\n\tDriverInfo() (map[string]interface{}, error)\n\n\t// Delete and detaches this endpoint from the network.\n\tDelete(force bool) error\n}\n```\nEndpoint represents a logical connection between a network and a sandbox.\n\n```go\ntype EndpointInfo interface {\n\t// Iface returns InterfaceInfo, go interface that can be used\n\t// to get more information on the interface which was assigned to\n\t// the endpoint by the driver. This can be used after the\n\t// endpoint has been created.\n\tIface() InterfaceInfo\n\n\t// Gateway returns the IPv4 gateway assigned by the driver.\n\t// This will only return a valid value if a container has joined the endpoint.\n\tGateway() net.IP\n\n\t// GatewayIPv6 returns the IPv6 gateway assigned by the driver.\n\t// This will only return a valid value if a container has joined the endpoint.\n\tGatewayIPv6() net.IP\n\n\t// StaticRoutes returns the list of static routes configured by the network\n\t// driver when the container joins a network\n\tStaticRoutes() []*types.StaticRoute\n\n\t// Sandbox returns the attached sandbox if there, nil otherwise.\n\tSandbox() Sandbox\n}\n```\nEndpointInfo provides an interface to retrieve network resources bound to the endpoint.\n\n```go\ntype EndpointOption func(ep *endpoint)\n```\nEndpointOption is a option setter function type used to pass varios options to Network and Endpoint interfaces methods. The various setter functions of type EndpointOption are provided by libnetwork, they look like \\\u003cCreate|Join|Leave\u003eOption\\[...](...)\n\n```go\nfunc CreateOptionAlias(name string, alias string) EndpointOption\n```\nCreateOptionAlias function returns an option setter for setting endpoint alias\n\n```go\nfunc CreateOptionAnonymous() EndpointOption\n```\nCreateOptionAnonymous function returns an option setter for setting this endpoint as anonymous\n\n```go\nfunc CreateOptionDisableResolution() EndpointOption\n```\nCreateOptionDisableResolution function returns an option setter to indicate this endpoint doesn't want embedded DNS server functionality\n\n```go\nfunc CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption\n```\nCreateOptionExposedPorts function returns an option setter for the container exposed ports option to be passed to network.CreateEndpoint() method.\n\n```go\nfunc CreateOptionIpam(ipV4, ipV6 net.IP, ipamOptions map[string]string) EndpointOption\n```\nCreateOptionIpam function returns an option setter for the ipam configuration for this endpoint\n\n```go\nfunc CreateOptionMyAlias(alias string) EndpointOption\n```\nCreateOptionMyAlias function returns an option setter for setting endpoint's self alias\n\n```go\nfunc CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption\n```\nCreateOptionPortMapping function returns an option setter for the mapping ports option to be passed to network.CreateEndpoint() method.\n\n```go\nfunc EndpointOptionGeneric(generic map[string]interface{}) EndpointOption\n```\nEndpointOptionGeneric function returns an option setter for a Generic option defined in a Dictionary of Key-Value pair\n\n```go\nfunc JoinOptionPriority(ep Endpoint, prio int) EndpointOption\n```\nJoinOptionPriority function returns an option setter for priority option to be passed to the endpoint.Join() method.\n\n```go\ntype EndpointWalker func(ep Endpoint) bool\n```\nEndpointWalker is a client provided function which will be used to walk the Endpoints. When the function returns true, the walk will stop.\n\n```go\ntype ErrInvalidConfigFile string\n```\nErrInvalidConfigFile type is returned when an invalid LibNetwork config file is detected\n\n```go\nfunc (cf ErrInvalidConfigFile) Error() string\n```\n\n```go\ntype ErrInvalidID string\n```\nErrInvalidID is returned when a query-by-id method is being invoked with an empty id parameter\n\n```go\nfunc (ii ErrInvalidID) BadRequest()\n```\nBadRequest denotes the type of this error\n\n```go\nfunc (ii ErrInvalidID) Error() string\n```\n\n```go\ntype ErrInvalidJoin struct{}\n```\nErrInvalidJoin is returned if a join is attempted on an endpoint which already has a container joined.\n\n```go\nfunc (ij ErrInvalidJoin) BadRequest()\n```\nBadRequest denotes the type of this error\n\n```go\nfunc (ij ErrInvalidJoin) Error() string\n```\n\n```go\ntype ErrInvalidName string\n```\nErrInvalidName is returned when a query-by-name or resource create method is invoked with an empty name parameter\n\n```go\nfunc (in ErrInvalidName) BadRequest()\n```\nBadRequest denotes the type of this error\n\n```go\nfunc (in ErrInvalidName) Error() string\n```\n\n```go\ntype ErrInvalidNetworkDriver string\n```\nErrInvalidNetworkDriver is returned if an invalid driver name is passed.\n\n```go\nfunc (ind ErrInvalidNetworkDriver) BadRequest()\n```\nBadRequest denotes the type of this error\n\n```go\nfunc (ind ErrInvalidNetworkDriver) Error() string\n```\n\n```go\ntype ErrNoContainer struct{}\n```\nErrNoContainer is returned when the endpoint has no container attached to it.\n\n```go\nfunc (nc ErrNoContainer) Error() string\n```\n\n```go\nfunc (nc ErrNoContainer) Maskable()\n```\nMaskable denotes the type of this error\n\n```go\ntype ErrNoSuchEndpoint string\n```\nErrNoSuchEndpoint is returned when a endpoint query finds no result\n\n```go\nfunc (nse ErrNoSuchEndpoint) Error() string\n```\n\n```go\nfunc (nse ErrNoSuchEndpoint) NotFound()\n```\nNotFound denotes the type of this error\n\n```go\ntype ErrNoSuchNetwork string\n```\nErrNoSuchNetwork is returned when a network query finds no result\n\n```go\nfunc (nsn ErrNoSuchNetwork) Error() string\n```\n\n```go\nfunc (nsn ErrNoSuchNetwork) NotFound()\n```\nNotFound denotes the type of this error\n\n```go\ntype InterfaceInfo interface {\n\t// MacAddress returns the MAC address assigned to the endpoint.\n\tMacAddress() net.HardwareAddr\n\n\t// Address returns the IPv4 address assigned to the endpoint.\n\tAddress() *net.IPNet\n\n\t// AddressIPv6 returns the IPv6 address assigned to the endpoint.\n\tAddressIPv6() *net.IPNet\n}\n```\nInterfaceInfo provides an interface to retrieve interface addresses bound to the endpoint.\n\n```go\ntype InvalidContainerIDError string\n```\nInvalidContainerIDError is returned when an invalid container id is passed in Join/Leave\n\n```go\nfunc (id InvalidContainerIDError) BadRequest()\n```\nBadRequest denotes the type of this error\n\n```go\nfunc (id InvalidContainerIDError) Error() string\n```\n\n```go\ntype IpamConf struct {\n\t// The master address pool for containers and network interfaces\n\tPreferredPool string\n\t// A subset of the master pool. If specified,\n\t// this becomes the container pool\n\tSubPool string\n\t// Preferred Network Gateway address (optional)\n\tGateway string\n\t// Auxiliary addresses for network driver. Must be within the master pool.\n\t// libnetwork will reserve them if they fall into the container pool\n\tAuxAddresses map[string]string\n}\n```\nIpamConf contains all the ipam related configurations for a network\n\n```go\nfunc (c *IpamConf) CopyTo(dstC *IpamConf) error\n```\nCopyTo deep copies to the destination IpamConfig\n\n```go\nfunc (c *IpamConf) Validate() error\n```\nValidate checks whether the configuration is valid\n\n```go\ntype IpamInfo struct {\n\tPoolID string\n\tMeta   map[string]string\n\tdriverapi.IPAMData\n}\n```\nIpamInfo contains all the ipam related operational info for a network\n\n```go\nfunc (i *IpamInfo) CopyTo(dstI *IpamInfo) error\n```\nCopyTo deep copies to the destination IpamInfo\n\n```go\nfunc (i *IpamInfo) MarshalJSON() ([]byte, error)\n```\nMarshalJSON encodes IpamInfo into json message\n\n```go\nfunc (i *IpamInfo) UnmarshalJSON(data []byte) error\n```\nUnmarshalJSON decodes json message into PoolData\n\n```go\ntype Network interface {\n\t// A user chosen name for this network.\n\tName() string\n\n\t// A system generated id for this network.\n\tID() string\n\n\t// The type of network, which corresponds to its managing driver.\n\tType() string\n\n\t// Create a new endpoint to this network symbolically identified by the\n\t// specified unique name. The options parameter carry driver specific options.\n\tCreateEndpoint(name string, options ...EndpointOption) (Endpoint, error)\n\n\t// Delete the network.\n\tDelete() error\n\n\t// Endpoints returns the list of Endpoint(s) in this network.\n\tEndpoints() []Endpoint\n\n\t// WalkEndpoints uses the provided function to walk the Endpoints\n\tWalkEndpoints(walker EndpointWalker)\n\n\t// EndpointByName returns the Endpoint which has the passed name. If not found, the error ErrNoSuchEndpoint is returned.\n\tEndpointByName(name string) (Endpoint, error)\n\n\t// EndpointByID returns the Endpoint which has the passed id. If not found, the error ErrNoSuchEndpoint is returned.\n\tEndpointByID(id string) (Endpoint, error)\n\n\t// Return certain operational data belonging to this network\n\tInfo() NetworkInfo\n}\n```\nA Network represents a logical connectivity zone that containers may join using the Link method. A Network is managed by a specific driver.\n\n```go\ntype NetworkController interface {\n\t// ID provides an unique identity for the controller\n\tID() string\n\n\t// Config method returns the bootup configuration for the controller\n\tConfig() config.Config\n\n\t// Create a new network. The options parameter carries network specific options.\n\tNewNetwork(networkType, name string, options ...NetworkOption) (Network, error)\n\n\t// Networks returns the list of Network(s) managed by this controller.\n\tNetworks() []Network\n\n\t// WalkNetworks uses the provided function to walk the Network(s) managed by this controller.\n\tWalkNetworks(walker NetworkWalker)\n\n\t// NetworkByName returns the Network which has the passed name. If not found, the error ErrNoSuchNetwork is returned.\n\tNetworkByName(name string) (Network, error)\n\n\t// NetworkByID returns the Network which has the passed id. If not found, the error ErrNoSuchNetwork is returned.\n\tNetworkByID(id string) (Network, error)\n\n\t// NewSandbox cretes a new network sandbox for the passed container id\n\tNewSandbox(containerID string, options ...SandboxOption) (Sandbox, error)\n\n\t// Sandboxes returns the list of Sandbox(s) managed by this controller.\n\tSandboxes() []Sandbox\n\n\t// WlakSandboxes uses the provided function to walk the Sandbox(s) managed by this controller.\n\tWalkSandboxes(walker SandboxWalker)\n\n\t// SandboxByID returns the Sandbox which has the passed id. If not found, a types.NotFoundError is returned.\n\tSandboxByID(id string) (Sandbox, error)\n\n\t// SandboxDestroy destroys a sandbox given a container ID\n\tSandboxDestroy(id string) error\n\n\t// Stop network controller\n\tStop()\n}\n```\nNetworkController provides the interface for controller instance which manages networks.\n\n```go\nfunc New(cfgOptions ...config.Option) (NetworkController, error)\n```\nNew creates a new instance of network controller.\n\n```go\ntype NetworkInfo interface {\n\tIpamConfig() (string, map[string]string, []*IpamConf, []*IpamConf)\n\tIpamInfo() ([]*IpamInfo, []*IpamInfo)\n\tDriverOptions() map[string]string\n\tScope() string\n\tInternal() bool\n}\n```\nNetworkInfo returns some configuration and operational information about the network\n\n```go\ntype NetworkNameError string\n```\nNetworkNameError is returned when a network with the same name already exists.\n\n```go\nfunc (nnr NetworkNameError) Error() string\n```\n\n```go\nfunc (nnr NetworkNameError) Forbidden()\n```\nForbidden denotes the type of this error\n\n```go\ntype NetworkOption func(n *network)\n```\nNetworkOption is a option setter function type used to pass varios options to NewNetwork method. The various setter functions of type NetworkOption are provided by libnetwork, they look like NetworkOptionXXXX(...)\n\n```go\nfunc NetworkOptionDeferIPv6Alloc(enable bool) NetworkOption\n```\nNetworkOptionDeferIPv6Alloc instructs the network to defer the IPV6 address allocation until after the endpoint has been created It is being provided to support the specific docker daemon flags where user can deterministically assign an IPv6 address to a container as combination of fixed-cidr-v6 + mac-address TODO: Remove this option setter once we support endpoint ipam options\n\n```go\nfunc NetworkOptionDriverOpts(opts map[string]string) NetworkOption\n```\nNetworkOptionDriverOpts function returns an option setter for any parameter described by a map\n\n```go\nfunc NetworkOptionGeneric(generic map[string]interface{}) NetworkOption\n```\nNetworkOptionGeneric function returns an option setter for a Generic option defined in a Dictionary of Key-Value pair\n\n```go\nfunc NetworkOptionInternalNetwork() NetworkOption\n```\nNetworkOptionInternalNetwork returns an option setter to config the network to be internal which disables default gateway service\n\n```go\nfunc NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption\n```\nNetworkOptionIpam function returns an option setter for the ipam configuration for this network\n\n```go\nfunc NetworkOptionPersist(persist bool) NetworkOption\n```\nNetworkOptionPersist returns an option setter to set persistence policy for a network\n\n```go\ntype NetworkTypeError string\n```\nNetworkTypeError type is returned when the network type string is not known to libnetwork.\n\n```go\nfunc (nt NetworkTypeError) Error() string\n```\n\n```go\nfunc (nt NetworkTypeError) NotFound()\n```\nNotFound denotes the type of this error\n\n```go\ntype NetworkWalker func(nw Network) bool\n```\nNetworkWalker is a client provided function which will be used to walk the Networks. When the function returns true, the walk will stop.\n\n```go\ntype Resolver interface {\n\t// Start starts the name server for the container\n\tStart() error\n\t// Stop stops the name server for the container. Stopped resolver\n\t// can be reused after running the SetupFunc again.\n\tStop()\n\t// SetupFunc() provides the setup function that should be run\n\t// in the container's network namespace.\n\tSetupFunc() func()\n\t// NameServer() returns the IP of the DNS resolver for the\n\t// containers.\n\tNameServer() string\n\t// To configure external name servers the resolver should use\n\tSetExtServers([]string)\n\t// ResolverOptions returns resolv.conf options that should be set\n\tResolverOptions() []string\n}\n```\nResolver represents the embedded DNS server in Docker. It operates by listening on container's loopback interface for DNS queries.\n\n```go\nfunc NewResolver(sb *sandbox) Resolver\n```\nNewResolver creates a new instance of the Resolver\n\n```go\ntype Sandbox interface {\n\t// ID returns the ID of the sandbox\n\tID() string\n\t// Key returns the sandbox's key\n\tKey() string\n\t// ContainerID returns the container id associated to this sandbox\n\tContainerID() string\n\t// Labels returns the sandbox's labels\n\tLabels() map[string]interface{}\n\t// Statistics retrieves the interfaces' statistics for the sandbox\n\tStatistics() (map[string]*types.InterfaceStatistics, error)\n\t// Refresh leaves all the endpoints, resets and re-apply the options,\n\t// re-joins all the endpoints without destroying the osl sandbox\n\tRefresh(options ...SandboxOption) error\n\t// SetKey updates the Sandbox Key\n\tSetKey(key string) error\n\t// Rename changes the name of all attached Endpoints\n\tRename(name string) error\n\t// Delete destroys this container after detaching it from all connected endpoints.\n\tDelete() error\n\t// ResolveName searches for the service name in the networks to which the sandbox\n\t// is connected to.\n\tResolveName(name string) net.IP\n\t// ResolveIP returns the service name for the passed in IP. IP is in reverse dotted\n\t// notation; the format used for DNS PTR records\n\tResolveIP(name string) string\n}\n```\nSandbox provides the control over the network container entity. It is a one to one mapping with the container.\n\n```go\ntype SandboxOption func(sb *sandbox)\n```\nSandboxOption is a option setter function type used to pass varios options to NewNetContainer method. The various setter functions of type SandboxOption are provided by libnetwork, they look like ContainerOptionXXXX(...)\n\n```go\nfunc OptionDNS(dns string) SandboxOption\n```\nOptionDNS function returns an option setter for dns entry option to be passed to container Create method.\n\n```go\nfunc OptionDNSOptions(options string) SandboxOption\n```\nOptionDNSOptions function returns an option setter for dns options entry option to be passed to container Create method.\n\n```go\nfunc OptionDNSSearch(search string) SandboxOption\n```\nOptionDNSSearch function returns an option setter for dns search entry option to be passed to container Create method.\n\n```go\nfunc OptionDomainname(name string) SandboxOption\n```\nOptionDomainname function returns an option setter for domainname option to be passed to NewSandbox method.\n\n```go\nfunc OptionExtraHost(name string, IP string) SandboxOption\n```\nOptionExtraHost function returns an option setter for extra /etc/hosts options which is a name and IP as strings.\n\n```go\nfunc OptionGeneric(generic map[string]interface{}) SandboxOption\n```\nOptionGeneric function returns an option setter for Generic configuration that is not managed by libNetwork but can be used by the Drivers during the call to net container creation method. Container Labels are a good example.\n\n```go\nfunc OptionHostname(name string) SandboxOption\n```\nOptionHostname function returns an option setter for hostname option to be passed to NewSandbox method.\n\n```go\nfunc OptionHostsPath(path string) SandboxOption\n```\nOptionHostsPath function returns an option setter for hostspath option to be passed to NewSandbox method.\n\n```go\nfunc OptionOriginHostsPath(path string) SandboxOption\n```\nOptionOriginHostsPath function returns an option setter for origin hosts file path tbeo  passed to NewSandbox method.\n\n```go\nfunc OptionOriginResolvConfPath(path string) SandboxOption\n```\nOptionOriginResolvConfPath function returns an option setter to set the path to the origin resolv.conf file to be passed to net container methods.\n\n```go\nfunc OptionParentUpdate(cid string, name, ip string) SandboxOption\n```\nOptionParentUpdate function returns an option setter for parent container which needs to update the IP address for the linked container.\n\n```go\nfunc OptionResolvConfPath(path string) SandboxOption\n```\nOptionResolvConfPath function returns an option setter for resolvconfpath option to be passed to net container methods.\n\n```go\nfunc OptionUseDefaultSandbox() SandboxOption\n```\nOptionUseDefaultSandbox function returns an option setter for using default sandbox to be passed to container Create method.\n\n```go\nfunc OptionUseExternalKey() SandboxOption\n```\nOptionUseExternalKey function returns an option setter for using provided namespace instead of creating one.\n\n```go\ntype SandboxWalker func(sb Sandbox) bool\n```\nSandboxWalker is a client provided function which will be used to walk the Sandboxes. When the function returns true, the walk will stop.\n\n```go\nfunc SandboxContainerWalker(out *Sandbox, containerID string) SandboxWalker\n```\nSandboxContainerWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed containerID\n\n```go\nfunc SandboxKeyWalker(out *Sandbox, key string) SandboxWalker\n```\nSandboxKeyWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed key\n\n```go\ntype UnknownEndpointError struct {\n\t// contains filtered or unexported fields\n}\n```\nUnknownEndpointError is returned when libnetwork could not find in it's database an endpoint with the same name and id.\n\n```go\nfunc (uee *UnknownEndpointError) Error() string\n```\n\n```go\nfunc (uee *UnknownEndpointError) NotFound()\n```\nNotFound denotes the type of this error\n\n```go\ntype UnknownNetworkError struct {\n\t// contains filtered or unexported fields\n}\n```\nUnknownNetworkError is returned when libnetwork could not find in it's database a network with the same name and id.\n\n```go\nfunc (une *UnknownNetworkError) Error() string\n```\n\n```go\nfunc (une *UnknownNetworkError) NotFound()\n```\nNotFound denotes the type of this error\n\n","path":"github.com/docker/libnetwork","name":"libnetwork","synopsis":"Package libnetwork provides the basic functionality and extension points to create network namespaces and allocate interfaces for containers to use.","isRedistributable":true}
