Docker Networking
ctelfer Merge pull request #2248 from AkihiroSuda/propagte-exec-root
allow propagating custom exec-root (e.g. "/run/docker") to libnetwork-setkey
Latest commit 20461b8 Sep 14, 2018
Permalink
Failed to load latest commit information.
.circleci circleci: Rename 'lint' to 'check' to match build target Jul 10, 2018
api Remove Solaris support Oct 25, 2017
bitseq doc: fix typo Sep 7, 2018
client Spelling fixes Jul 12, 2018
cluster Switch from x/net/context -> context Apr 24, 2018
cmd doc: fix typo Sep 7, 2018
config allow propagating custom exec-root (e.g. "/run/docker") to libnetwork… Sep 14, 2018
datastore Spelling fixes Jul 12, 2018
diagnostic doc: fix typo Sep 7, 2018
discoverapi fix nits in comments and log Oct 29, 2016
docs Spelling fixes Jul 12, 2018
driverapi Spelling fixes Jul 12, 2018
drivers Fix typo: assigment -> assignment Sep 13, 2018
drvregistry Spelling fixes Jul 12, 2018
etchosts Enable network-db test image creation May 29, 2018
hostdiscovery test: fix ineffectual assignments May 29, 2018
idm Adding a unit case to verify rollover Oct 3, 2017
internal Create internal directory Jul 17, 2018
ipam Fix some typos Sep 8, 2018
ipamapi Adding a unit case to verify rollover Oct 3, 2017
ipams Global Default Address Pool support Aug 16, 2018
ipamutils Add getter function for Default Address Pools Aug 16, 2018
iptables Spelling fixes Jul 12, 2018
ipvs ipvs support rs connection information Aug 22, 2018
netlabel Support for com.docker.network.bridge.container_interface_prefix label Mar 1, 2017
netutils Global Default Address Pool support Aug 16, 2018
networkdb fix error when make lint Sep 8, 2018
ns Add init_windows.go for compilation Sep 13, 2018
options use grep to find a/an misuse Jun 3, 2016
osl doc: fix typo Sep 7, 2018
portallocator Don't build portallocator on Windows Sep 13, 2018
portmapper Support SCTP port mapping Feb 13, 2018
resolvconf Fix handling of the resolv.conf Jul 24, 2018
support Added support for Swarm Service Driller (ssd) Aug 16, 2018
test/integration doc: fix typo Sep 7, 2018
testutils Remove Solaris support Oct 25, 2017
types Migrate to gotest.tools :) Jul 6, 2018
vendor Bump libkv to 458977154600b9f23984d9f4b82e79570b5ae12b Sep 13, 2018
.dockerignore Added back dockerignore Jun 22, 2018
.gitignore Added back dockerignore Jun 22, 2018
CHANGELOG.md Spelling fixes Jul 12, 2018
Dockerfile Dockerfile: Install a fixed version of gogoprotobuf Jul 25, 2018
LICENSE Initial commit Feb 20, 2015
MAINTAINERS Maintainers update May 18, 2018
Makefile Make protobuf check silent Jul 12, 2018
README.md Add required imports to example code in README.md Jul 16, 2018
ROADMAP.md fix typos May 30, 2016
Vagrantfile Updated vagrant box, ubuntu/vivid64 was remove from atlas.hasicorp.com Oct 19, 2016
agent.go Spelling fixes Jul 12, 2018
agent.pb.go Gracefully remove LB endpoints from services Mar 16, 2018
agent.proto Gracefully remove LB endpoints from services Mar 16, 2018
controller.go Give LB sandboxes predictable names Jul 24, 2018
default_gateway.go Avoid default gateway collisions Jun 28, 2018
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_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 Allow user to specify default address pools for docker networks Feb 22, 2018
drivers_linux.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 Add endpoint load-balancing mode Jun 28, 2018
endpoint_cnt.go endpoint_cnt store updates should not create an object Oct 27, 2017
endpoint_info.go Add SrcName() method to return interface name Jun 28, 2018
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 Reload DOCKER-USER chain on frewalld reload. Jan 12, 2018
firewall_others.go Reload DOCKER-USER chain on frewalld reload. Jan 12, 2018
libnetwork_internal_test.go Create internal directory Jul 17, 2018
libnetwork_linux_test.go Fix handling of the resolv.conf Jul 24, 2018
libnetwork_test.go Spelling fixes Jul 12, 2018
machines Use Docker Machine for Test Environments Nov 10, 2015
network.go Merge pull request #2240 from ctelfer/nice-lb-names Jul 25, 2018
network_unix.go Windows overlay driver support Nov 3, 2016
network_windows.go Fix for docker intercepting DNS requests on ICS network Nov 17, 2017
resolver.go Spelling fixes Jul 12, 2018
resolver_test.go Retry other external DNS servers on ServFail Mar 23, 2018
resolver_unix.go Rolling back the port configs if failed to programIngress() Sep 11, 2018
resolver_windows.go Move the iptables setup for embedded DNS into a reexec process Apr 16, 2016
sandbox.go Merge pull request #2240 from ctelfer/nice-lb-names Jul 25, 2018
sandbox_dns_unix.go Fix handling of the resolv.conf Jul 24, 2018
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_unix.go allow propagating custom exec-root (e.g. "/run/docker") to libnetwork… Sep 14, 2018
sandbox_externalkey_windows.go Fix netns path setting from hook Mar 16, 2016
sandbox_store.go Use fmt precision to limit string length Jul 5, 2018
sandbox_test.go Improve interface order May 25, 2018
service.go Create internal directory Jul 17, 2018
service_common.go Create internal directory Jul 17, 2018
service_common_test.go Migrate to gotest.tools :) Jul 6, 2018
service_linux.go Rolling back the port configs if failed to programIngress() Sep 11, 2018
service_unsupported.go Add endpoint load-balancing mode Jun 28, 2018
service_windows.go Add endpoint load-balancing mode Jun 28, 2018
store.go Add option processing to network.Delete() Jun 28, 2018
store_linux_test.go libnetwork support for Solaris Oct 14, 2016
store_test.go libnetwork support for Solaris Oct 14, 2016
vendor.conf Remove unused syndtr/gocapability from vendor.conf Sep 13, 2018

README.md

libnetwork - networking for containers

Circle CI Coverage Status GoDoc Go Report Card

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.

import (
	"fmt"
	"log"

	"github.com/docker/docker/pkg/reexec"
	"github.com/docker/libnetwork"
	"github.com/docker/libnetwork/config"
	"github.com/docker/libnetwork/netlabel"
	"github.com/docker/libnetwork/options"
)

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.