Categorygithub.com/cloudnativelabs/libnetwork
modulepackage
0.8.0-dev.2
Repository: https://github.com/cloudnativelabs/libnetwork.git
Documentation: pkg.go.dev

# README

libnetwork - networking for containers

Circle CI Coverage Status GoDoc

Libnetwork provides a native Go implementation for connecting containers

The goal of libnetwork is to deliver a robust Container Network Model that provides a consistent programming interface and the required network abstractions for applications.

Design

Please refer to the design for more information.

Using libnetwork

There are many networking solutions available to suit a broad range of use-cases. libnetwork uses a driver / plugin model to support all of these solutions while abstracting the complexity of the driver implementations by exposing a simple and consistent Network Model to users.

func main() {
	if reexec.Init() {
		return
	}

	// Select and configure the network driver
	networkType := "bridge"

	// Create a new controller instance
	driverOptions := options.Generic{}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = driverOptions
	controller, err := libnetwork.New(config.OptionDriverConfig(networkType, genericOption))
	if err != nil {
		log.Fatalf("libnetwork.New: %s", err)
	}

	// Create a network for containers to join.
	// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can use.
	network, err := controller.NewNetwork(networkType, "network1", "")
	if err != nil {
		log.Fatalf("controller.NewNetwork: %s", err)
	}

	// For each new container: allocate IP and interfaces. The returned network
	// settings will be used for container infos (inspect and such), as well as
	// iptables rules for port publishing. This info is contained or accessible
	// from the returned endpoint.
	ep, err := network.CreateEndpoint("Endpoint1")
	if err != nil {
		log.Fatalf("network.CreateEndpoint: %s", err)
	}

	// Create the sandbox for the container.
	// NewSandbox accepts Variadic optional arguments which libnetwork can use.
	sbx, err := controller.NewSandbox("container1",
		libnetwork.OptionHostname("test"),
		libnetwork.OptionDomainname("docker.io"))
	if err != nil {
		log.Fatalf("controller.NewSandbox: %s", err)
	}

	// A sandbox can join the endpoint via the join api.
	err = ep.Join(sbx)
	if err != nil {
		log.Fatalf("ep.Join: %s", err)
	}

	// libnetwork client can check the endpoint's operational data via the Info() API
	epInfo, err := ep.DriverInfo()
	if err != nil {
		log.Fatalf("ep.DriverInfo: %s", err)
	}

	macAddress, ok := epInfo[netlabel.MacAddress]
	if !ok {
		log.Fatalf("failed to get mac address from endpoint info")
	}

	fmt.Printf("Joined endpoint %s (%s) to sandbox %s (%s)\n", ep.Name(), macAddress, sbx.ContainerID(), sbx.Key())
}

Future

Please refer to roadmap for more information.

Contributing

Want to hack on libnetwork? Docker's contributions guidelines apply.

Copyright and license

Code and documentation copyright 2015 Docker, inc. Code released under the Apache 2.0 license. Docs released under Creative commons.

# Packages

No description provided by the author
Package bitseq provides a structure and utilities for representing long bitmask as sequence of run-lenght encoded blocks.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package idm manages reservation/release of numerical ids from a configured set of contiguous ids.
No description provided by the author
Package ipamapi specifies the contract the IPAM service (built-in or remote) needs to satisfy.
No description provided by the author
Package ipamutils provides utililty functions for ipam management.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package options provides a way to pass unstructured sets of options to a component expecting a strongly-typed configuration structure.
Package osl describes structures and interfaces which abstract os entities.
No description provided by the author
No description provided by the author
Package resolvconf provides utility code to query and update DNS configuration in /etc/resolv.conf.
No description provided by the author
Package types contains types that are common across libnetwork project.

# Functions

CreateOptionAlias function returns an option setter for setting endpoint alias.
CreateOptionAnonymous function returns an option setter for setting this endpoint as anonymous.
CreateOptionDisableResolution function returns an option setter to indicate this endpoint doesn't want embedded DNS server functionality.
CreateOptionExposedPorts function returns an option setter for the container exposed ports option to be passed to network.CreateEndpoint() method.
CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint.
CreateOptionMyAlias function returns an option setter for setting endpoint's self alias.
CreateOptionPortMapping function returns an option setter for the mapping ports option to be passed to network.CreateEndpoint() method.
EndpointOptionGeneric function returns an option setter for a Generic option defined in a Dictionary of Key-Value pair.
JoinOptionPriority function returns an option setter for priority option to be passed to the endpoint.Join() method.
NetworkOptionDeferIPv6Alloc 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.
NetworkOptionDriverOpts function returns an option setter for any driver parameter described by a map.
NetworkOptionEnableIPv6 returns an option setter to explicitly configure IPv6.
NetworkOptionGeneric function returns an option setter for a Generic option defined in a Dictionary of Key-Value pair.
NetworkOptionInternalNetwork returns an option setter to config the network to be internal which disables default gateway service.
NetworkOptionIpam function returns an option setter for the ipam configuration for this network.
NetworkOptionLabels function returns an option setter for labels specific to a network.
NetworkOptionPersist returns an option setter to set persistence policy for a network.
New creates a new instance of network controller.
NewResolver creates a new instance of the Resolver.
OptionDNS function returns an option setter for dns entry option to be passed to container Create method.
OptionDNSOptions function returns an option setter for dns options entry option to be passed to container Create method.
OptionDNSSearch function returns an option setter for dns search entry option to be passed to container Create method.
OptionDomainname function returns an option setter for domainname option to be passed to NewSandbox method.
OptionExposedPorts function returns an option setter for the container exposed ports option to be passed to container Create method.
OptionExtraHost function returns an option setter for extra /etc/hosts options which is a name and IP as strings.
OptionGeneric 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.
OptionHostname function returns an option setter for hostname option to be passed to NewSandbox method.
OptionHostsPath function returns an option setter for hostspath option to be passed to NewSandbox method.
OptionOriginHostsPath function returns an option setter for origin hosts file path tbeo passed to NewSandbox method.
OptionOriginResolvConfPath function returns an option setter to set the path to the origin resolv.conf file to be passed to net container methods.
OptionParentUpdate function returns an option setter for parent container which needs to update the IP address for the linked container.
OptionPortMapping function returns an option setter for the mapping ports option to be passed to container Create method.
OptionResolvConfPath function returns an option setter for resolvconfpath option to be passed to net container methods.
OptionUseDefaultSandbox function returns an option setter for using default sandbox to be passed to container Create method.
OptionUseExternalKey function returns an option setter for using provided namespace instead of creating one.
SandboxContainerWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed containerID.
SandboxKeyWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed key.
SetExternalKey provides a convenient way to set an External key to a sandbox.

# Structs

ActiveContainerError is returned when an endpoint is deleted which has active containers attached to it.
ActiveEndpointsError is returned when a network is deleted which has active endpoints in it.
ErrInvalidJoin is returned if a join is attempted on an endpoint which already has a container joined.
ErrNoContainer is returned when the endpoint has no container attached to it.
IpamConf contains all the ipam related configurations for a network.
IpamInfo contains all the ipam related operational info for a network.
UnknownEndpointError is returned when libnetwork could not find in it's database an endpoint with the same name and id.
UnknownNetworkError is returned when libnetwork could not find in it's database a network with the same name and id.

# Interfaces

Endpoint represents a logical connection between a network and a sandbox.
EndpointInfo provides an interface to retrieve network resources bound to the endpoint.
InterfaceInfo provides an interface to retrieve interface addresses bound to the endpoint.
A Network represents a logical connectivity zone that containers may join using the Link method.
NetworkController provides the interface for controller instance which manages networks.
NetworkInfo returns some configuration and operational information about the network.
Resolver represents the embedded DNS server in Docker.
Sandbox provides the control over the network container entity.

# Type aliases

EndpointOption is an option setter function type used to pass various options to Network and Endpoint interfaces methods.
EndpointWalker is a client provided function which will be used to walk the Endpoints.
ErrInvalidConfigFile type is returned when an invalid LibNetwork config file is detected.
ErrInvalidID is returned when a query-by-id method is being invoked with an empty id parameter.
ErrInvalidName is returned when a query-by-name or resource create method is invoked with an empty name parameter.
ErrInvalidNetworkDriver is returned if an invalid driver name is passed.
ErrNoSuchEndpoint is returned when a endpoint query finds no result.
ErrNoSuchNetwork is returned when a network query finds no result.
InvalidContainerIDError is returned when an invalid container id is passed in Join/Leave.
NetworkNameError is returned when a network with the same name already exists.
NetworkOption is an option setter function type used to pass various options to NewNetwork method.
NetworkTypeError type is returned when the network type string is not known to libnetwork.
NetworkWalker is a client provided function which will be used to walk the Networks.
SandboxOption is an option setter function type used to pass various options to NewNetContainer method.
SandboxWalker is a client provided function which will be used to walk the Sandboxes.