Docker Networking
Go Shell Other
Latest commit c3393f1 Jul 21, 2017 @mavenugo mavenugo committed on GitHub Merge pull request #1846 from fcrisciani/avoid-test-failure
Avoid flakiness of TestLinkContainers
Permalink
Failed to load latest commit information.
api Fixed code issues Jun 12, 2017
bitseq Merge pull request #1568 from likel/refactor Dec 29, 2016
client Fixed code issues Jun 12, 2017
cluster use builtin package context rather than vendored one Jul 13, 2017
cmd use builtin package context rather than vendored one Jul 13, 2017
common Service discovery race on serviceBindings delete. Bug on IP reuse (#1808 Jun 18, 2017
config Revert "Move Cluster provider back to Moby" May 25, 2017
datastore Fixed code issues Jun 12, 2017
discoverapi fix nits in comments and log Oct 29, 2016
docs Add ConnectivityScope capability for network drivers along with scope… May 13, 2017
driverapi Add ConnectivityScope capability for network drivers along with scope… May 13, 2017
drivers Avoid flakiness of TestLinkContainers Jul 21, 2017
drvregistry swarm mode network inspect should provide cluser-wide task details Mar 11, 2017
etchosts Fix file descriptor leaks Jul 1, 2016
hostdiscovery Remove unnecessary string formats Nov 22, 2016
idm Merge pull request #1568 from likel/refactor Dec 29, 2016
ipam Fixed code issues Jun 12, 2017
ipamapi Internal interface to differentiate built-in drivers from remote Dec 19, 2016
ipams Fixed code issues Jun 12, 2017
ipamutils use grep to find a/an misuse Jun 3, 2016
iptables Avoid flakiness of TestLinkContainers Jul 21, 2017
ipvs fix review comments May 25, 2017
netlabel Support for com.docker.network.bridge.container_interface_prefix label Mar 1, 2017
netutils Remove unnecessary string formats Nov 22, 2016
networkdb NetworkDB incorrect number of entries in networkNodes Jul 18, 2017
ns Flush container flows in conntrack (Bug #8795) Apr 8, 2017
options use grep to find a/an misuse Jun 3, 2016
osl Fixed code issues Jun 12, 2017
portallocator Fixed code issues Jun 12, 2017
portmapper libnetwork support for Solaris Oct 14, 2016
resolvconf Fix GetNameServerAsCIDR Jan 26, 2017
test/integration Provide a way for libnetwork to make use of Agent mode functionalities Jun 6, 2016
testutils Fixed code issues Jun 12, 2017
types Merge pull request #1205 from allencloud/fix-typos Aug 1, 2016
vendor Vendoring netlink library Jun 6, 2017
.dockerignore Multi-Arch Support Nov 25, 2015
.gitignore IPAM to run consistency check over its bitmasks Jan 14, 2016
CHANGELOG.md Changelog for 0.8.0-dev.2 May 7, 2016
Dockerfile.build Add gosimple check Jul 6, 2017
LICENSE Initial commit Feb 20, 2015
MAINTAINERS Flavio as Libnetwork maintainer Jun 17, 2017
Makefile Add gosimple check Jul 6, 2017
README.md Add support to accepting arbitrary network ID Apr 15, 2016
ROADMAP.md fix typos May 30, 2016
Vagrantfile Updated vagrant box, ubuntu/vivid64 was remove from atlas.hasicorp.com Oct 19, 2016
agent.go Add gosimple check Jul 6, 2017
agent.pb.go Add container short-id as an alias for swarm mode tasks Aug 3, 2016
agent.proto Service discovery logic rework Jun 12, 2017
circle.yml Force go 1.7.1 in circle.yml to resolve failure to get golint Oct 12, 2016
controller.go Fixed code issues Jun 12, 2017
default_gateway.go Remove gw endpoint on gw nw join failure Apr 12, 2017
default_gateway_freebsd.go Default GW support for overlay networks Nov 8, 2016
default_gateway_linux.go Default GW support for overlay networks Nov 8, 2016
default_gateway_solaris.go Default GW support for overlay networks Nov 8, 2016
default_gateway_windows.go Default GW support for overlay networks Nov 8, 2016
drivers_experimental_linux.go Handling the new experimental daemon flag Dec 13, 2016
drivers_freebsd.go Handling the new experimental daemon flag Dec 13, 2016
drivers_ipam.go Moving IPAM initalization out of drvRegistry into libnetwork core Jul 5, 2016
drivers_linux.go Handling the new experimental daemon flag Dec 13, 2016
drivers_solaris.go Handling the new experimental daemon flag Dec 13, 2016
drivers_windows.go Changes to support ICS network on windows May 18, 2017
endpoint.go Service discovery logic rework Jun 12, 2017
endpoint_cnt.go Fix endpoint cnt decline overflow Jul 15, 2016
endpoint_info.go Add gosimple check Jul 6, 2017
endpoint_info_unix.go Default GW support for overlay networks Nov 8, 2016
endpoint_info_windows.go Default GW support for overlay networks Nov 8, 2016
error.go Merge pull request #1616 from chchliang/testnetwork Apr 10, 2017
errors_test.go Provide interface to categorize errors May 21, 2015
firewall_linux.go Add a filter chain to allow persistent rules May 16, 2017
firewall_others.go Add a filter chain to allow persistent rules May 16, 2017
libnetwork_internal_test.go Service discovery race on serviceBindings delete. Bug on IP reuse (#1808 Jun 18, 2017
libnetwork_linux_test.go Add gosimple check Jul 6, 2017
libnetwork_test.go Add gosimple check Jul 6, 2017
machines Use Docker Machine for Test Environments Nov 10, 2015
network.go Add gosimple check Jul 6, 2017
network_unix.go Windows overlay driver support Nov 3, 2016
network_windows.go Fix debug statement in startResolver Jul 17, 2017
resolver.go Add gosimple check Jul 6, 2017
resolver_unix.go Refactoring logrus import and formatting Nov 8, 2016
resolver_windows.go Move the iptables setup for embedded DNS into a reexec process Apr 16, 2016
sandbox.go Add gosimple check Jul 6, 2017
sandbox_dns_unix.go Fix the data model inconsistency that breaks daemon upgrade to 1.14-dev Jan 19, 2017
sandbox_dns_windows.go Setup external DNS servers after daemon restart with live-restore Jun 10, 2016
sandbox_externalkey.go sandbox_externalkey.go: split for cross compilation Nov 25, 2015
sandbox_externalkey_solaris.go Get libnetwork to build on Solaris Apr 14, 2016
sandbox_externalkey_unix.go Add gosimple check Jul 6, 2017
sandbox_externalkey_windows.go Fix netns path setting from hook Mar 16, 2016
sandbox_store.go Add gosimple check Jul 6, 2017
sandbox_test.go Check subnet overlap when programming of sandbox interface Nov 8, 2016
service.go Service discovery race on serviceBindings delete. Bug on IP reuse (#1808 Jun 18, 2017
service_common.go Service discovery race on serviceBindings delete. Bug on IP reuse (#1808 Jun 18, 2017
service_linux.go Service discovery race on serviceBindings delete. Bug on IP reuse (#1808 Jun 18, 2017
service_unsupported.go Windows overlay driver support Nov 3, 2016
service_windows.go Make virtual service programming more robust Feb 1, 2017
store.go Do not reset network scope during store read May 15, 2017
store_linux_test.go libnetwork support for Solaris Oct 14, 2016
store_test.go libnetwork support for Solaris Oct 14, 2016
support.sh Add network inspect -v to the support script May 11, 2017
vendor.conf Vendoring netlink library Jun 6, 2017
wrapmake.sh Allow tests to be interrupted Sep 2, 2015

README.md

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.