Docker Networking
Go Shell Other
Latest commit a193122 Jan 12, 2017 @mavenugo mavenugo committed on GitHub Merge pull request #1615 from sanimej/godep
Use vndr for managing libnetwork dependencies
Permalink
Failed to load latest commit information.
api Remove unnecessary string formats Nov 22, 2016
bitseq Merge pull request #1568 from likel/refactor Dec 29, 2016
client Remove unnecessary string formats Nov 22, 2016
cluster Honor user provided listen address for gossip Sep 22, 2016
cmd Merge pull request #1598 from AkihiroSuda/tcp-halfclose-docker-27539 Jan 6, 2017
config Handling the new experimental daemon flag Dec 13, 2016
datastore Remove unnecessary string formats Nov 22, 2016
discoverapi fix nits in comments and log Oct 29, 2016
docs Merge pull request #1471 from datastream/patch-1 Jan 5, 2017
driverapi Merge pull request #1604 from allencloud/fix-nits-in-comments Dec 29, 2016
drivers return an error on overlay subnet is overlapped with hosts Jan 5, 2017
drvregistry Merge pull request #1568 from likel/refactor Dec 29, 2016
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 Merge pull request #1568 from likel/refactor Dec 29, 2016
ipamapi Internal interface to differentiate built-in drivers from remote Dec 19, 2016
ipams Merge pull request #1599 from mavenugo/v0.9 Jan 4, 2017
ipamutils use grep to find a/an misuse Jun 3, 2016
iptables Merge pull request #1568 from likel/refactor Dec 29, 2016
ipvs Fixed misspelling Nov 28, 2016
netlabel DNS support Sep 20, 2016
netutils Remove unnecessary string formats Nov 22, 2016
networkdb Merge pull request #1568 from likel/refactor Dec 29, 2016
ns Set a timeout on the netlink handle sockets Nov 15, 2016
options use grep to find a/an misuse Jun 3, 2016
osl Control IPv6 on container's interface Nov 22, 2016
portallocator libnetwork support for Solaris Oct 14, 2016
portmapper libnetwork support for Solaris Oct 14, 2016
resolvconf Merge pull request #1595 from sanimej/host Jan 5, 2017
test/integration Provide a way for libnetwork to make use of Agent mode functionalities Jun 6, 2016
testutils libnetwork support for Solaris Oct 14, 2016
types Merge pull request #1205 from allencloud/fix-typos Aug 1, 2016
vendor Use vndr for managing libnetwork dependencies Jan 12, 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 WIP: Update golang version to 1.7.1 Oct 4, 2016
LICENSE Initial commit Feb 20, 2015
MAINTAINERS Chen Chun as libnetwork maintainer Feb 22, 2016
Makefile Use vndr for managing libnetwork dependencies Jan 12, 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 missing locks in agent and service code Nov 29, 2016
agent.pb.go Add container short-id as an alias for swarm mode tasks Aug 3, 2016
agent.proto Add container short-id as an alias for swarm mode tasks Aug 3, 2016
circle.yml Force go 1.7.1 in circle.yml to resolve failure to get golint Oct 12, 2016
controller.go carry docker/docker #29564 Jan 10, 2017
default_gateway.go Fix bug in needDefaultGW() Nov 20, 2016
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 Handling the new experimental daemon flag Dec 13, 2016
endpoint.go Revert "Enable ping for service vip address" Nov 21, 2016
endpoint_cnt.go Fix endpoint cnt decline overflow Jul 15, 2016
endpoint_info.go Fix bug in link-local unmarshalling Nov 21, 2016
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 #1510 from allencloud/validate-network-and-endpoin… Nov 2, 2016
errors_test.go Provide interface to categorize errors May 21, 2015
libnetwork_internal_test.go Merge pull request #1586 from sanimej/ptr Dec 21, 2016
libnetwork_linux_test.go fix nits in comments Dec 28, 2016
libnetwork_test.go Merge pull request #1531 from daehyeok/logrus_formating Nov 8, 2016
machines Use Docker Machine for Test Environments Nov 10, 2015
network.go Merge pull request #1605 from sanimej/slice Dec 29, 2016
network_unix.go Windows overlay driver support Nov 3, 2016
network_windows.go Fixed misspelling Nov 28, 2016
resolver.go Merge pull request #1595 from sanimej/host Jan 5, 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 Merge pull request #1609 from aboch/gw46 Jan 5, 2017
sandbox_dns_unix.go Merge pull request #1595 from sanimej/host Jan 5, 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 Moving the UDS file out of /var/lib/docker and into /run/ Jul 15, 2016
sandbox_externalkey_windows.go Fix netns path setting from hook Mar 16, 2016
sandbox_store.go Add embedded DNS server support for host loopback resolver Dec 22, 2016
sandbox_test.go Check subnet overlap when programming of sandbox interface Nov 8, 2016
service.go Cleanup service bindings when leaving cluster Aug 20, 2016
service_common.go Add missing locks in agent and service code Nov 29, 2016
service_linux.go Add missing locks in agent and service code Nov 29, 2016
service_unsupported.go Windows overlay driver support Nov 3, 2016
service_windows.go Windows overlay driver support Nov 3, 2016
store.go Refactoring logrus import and formatting Nov 8, 2016
store_linux_test.go libnetwork support for Solaris Oct 14, 2016
store_test.go libnetwork support for Solaris Oct 14, 2016
support.sh Simple support script to gather libnetwork info Aug 23, 2016
vendor.conf Use vndr for managing libnetwork dependencies Jan 12, 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.