Skip to content
Docker Networking
Go Shell Makefile
Latest commit 6d1a65c @aboch aboch Merge pull request #974 from sanimej/RR
Embedded DNS server to return multiple A records for enabling DNS Round Robin
Failed to load latest commit information.
Godeps Merge pull request #969 from fudanchii/bump-netlink
api Fix some typos in comments and strings
bitseq Fix some typos in comments and strings
client Don't allow passing EnableIPv6 as a driver option (a label)
cmd Use gofmt with -s instead of goimports
config Allow to pass global datastore config
datastore Fix some typos.
discoverapi Fix some typos.
docs Fix IPAM driver documentation
driverapi Fix some typos in comments and strings
drivers Merge pull request #803 from aboch/pm
etchosts Extract hostname from (hostname.domainname)
hostdiscovery Use gofmt with -s instead of goimports
idm Fix some typos.
ipam Fix some typos.
ipamapi Add nil ipam driver
ipams Merge pull request #970 from chenchun/nil
ipamutils Allow libnetwork to compile on freebsd
iptables Fix iptables.Exists logic
netlabel Handle datastore update in Ipam and overlay drivers
netutils Retain V6 DNS server in resolv.conf; use only V4 servers for fallback
ns Move test specific functions to a testutils package.
options Move test specific functions to a testutils package.
osl Merge pull request #803 from aboch/pm
portallocator Move test specific functions to a testutils package.
portmapper Use gofmt with -s instead of goimports
resolvconf Retain V6 DNS server in resolv.conf; use only V4 servers for fallback
test/integration Fix some typos in comments and strings
testutils Fixed build tags for linux files
types Fix some typos.
.dockerignore Multi-Arch Support
.gitignore IPAM to run consistency check over its bitmasks
CHANGELOG.md Fix some typos in comments and strings
Dockerfile.build Use gofmt with -s instead of goimports
LICENSE Initial commit
MAINTAINERS Chen Chun as libnetwork maintainer
Makefile Use gofmt with -s instead of goimports
README.md Fix up example code
ROADMAP.md Update ROADMAP.md
Vagrantfile Fixed Vagrantfile to use systemd script
circle.yml Multi-Arch Support
controller.go Fix some typos in comments and strings
default_gateway.go Handle concurrent creation of default GW network
default_gateway_freebsd.go Made use of map[string]string for nw options in default-gateway impl
default_gateway_linux.go Don't allow passing EnableIPv6 as a driver option (a label)
default_gateway_windows.go Made use of map[string]string for nw options in default-gateway impl
drivers.go Add nil ipam driver
drivers_freebsd.go Push driver config during `Init`
drivers_linux.go Push driver config during `Init`
drivers_windows.go Renaming driver name to lower case for usability and allowing portmap…
endpoint.go Fix some races in getNetworkFromStore
endpoint_cnt.go Some functions' logic cleanup
endpoint_info.go Force delete sandbox during sandboxCleanup
error.go Fixed a couple of error messages to address UX related comments
errors_test.go Provide interface to categorize errors
libnetwork_internal_test.go Fix some typos in comments and strings
libnetwork_test.go Implement DNS RR in the Docker embedded DNS server
machines Use Docker Machine for Test Environments
network.go Fix some typos in comments and strings
resolver.go Implement DNS RR in the Docker embedded DNS server
sandbox.go Merge pull request #974 from sanimej/RR
sandbox_dns_unix.go Windows HNS integration
sandbox_dns_windows.go Windows HNS integration
sandbox_externalkey.go sandbox_externalkey.go: split for cross compilation
sandbox_externalkey_unix.go Fix some typos in comments and strings
sandbox_externalkey_windows.go sandbox_externalkey.go: split for cross compilation
sandbox_store.go Force delete sandbox during sandboxCleanup
sandbox_test.go expose Endpoints API for a Sandbox
store.go Merge pull request #908 from aboch/dds
store_test.go Add customer_prefix to the store URL for integration test
wrapmake.sh Allow tests to be interrupted

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.

Something went wrong with that request. Please try again.