Sebastiaan van Stijn 02dc5ea720 libnetwork/datastore: remove Store.KVStore() 1 year ago
..
bitmap 564a13285f libnetwork/bitmap: improve documentation 2 years ago
cluster 0f6cb61f2d Switch from x/net/context -> context 7 years ago
cmd 332ffe8d74 libnetwork/networkdb: NetworkDB.Watch(): remove unused "key" argument 2 years ago
config 738b16d873 libnetwork/config: add Config.DriverConfig() and un-export DriverCfg 2 years ago
datastore 02dc5ea720 libnetwork/datastore: remove Store.KVStore() 1 year ago
diagnostic 74da6a6363 Switch all logging to use containerd log pkg 2 years ago
discoverapi a08a254df3 libnetwork: drop DatastoreConfig discovery type 2 years ago
docs 9e817251a8 libnetwork/docs: fix broken link 2 years ago
driverapi 5b3acc15d1 libnetwork: drop legacy driver cruft 2 years ago
drivers 37cbdeb1f2 libnetwork: remove most of kvstore 1 year ago
drvregistry 5b3acc15d1 libnetwork: drop legacy driver cruft 2 years ago
etchosts 1cd937a867 libnetwork/etchosts: format code with gofumpt 2 years ago
internal 37cbdeb1f2 libnetwork: remove most of kvstore 1 year ago
ipam 6f3fcbcfe1 libnetwork/ipam(s): format code with gofumpt 2 years ago
ipamapi 5b3acc15d1 libnetwork: drop legacy driver cruft 2 years ago
ipams 5b3acc15d1 libnetwork: drop legacy driver cruft 2 years ago
ipamutils bba21735bf libnetwork/ipamutils: format code with gofumpt 2 years ago
ipbits 3c59ef247f libnet/ipam: use netip types internally 2 years ago
iptables ddd33c6bbd libnetwork/iptables: move IPTable.LoopbackByVersion() to a utility 2 years ago
netlabel 644e3d4cdb libnetwork/netlabel: remove dead code 2 years ago
netutils 65e2149b3e libnetwork/netutils: format code with gofumpt 2 years ago
networkdb 332ffe8d74 libnetwork/networkdb: NetworkDB.Watch(): remove unused "key" argument 2 years ago
ns 74da6a6363 Switch all logging to use containerd log pkg 2 years ago
options 948f55d0b7 libnetwork/options: remove unused NewGeneric, and use map[string]any 2 years ago
osl 882f7bbf1f libnetwork/osl: format code with gofumpt 2 years ago
portallocator 801cd50744 libnetwork/portallocator: format code with gofumpt 2 years ago
portmapper dd5ea7e996 libnetwork: format code with gofumpt 2 years ago
resolvconf 0b75c02276 libnetwork/resolvconf: format code with gofumpt 2 years ago
support 4b981436fe Fixup libnetwork lint errors 4 years ago
testutils ecbd126d6a Merge pull request #45586 from corhere/fix-flaky-resolver-test 2 years ago
types dd5ea7e996 libnetwork: format code with gofumpt 2 years ago
.dockerignore 62ebaeac7a Added back dockerignore 7 years ago
.gitignore 62ebaeac7a Added back dockerignore 7 years ago
README.md 17882ed614 libnetwork: update example in README.md 2 years ago
agent.go 64c6f72988 libnetwork: remove Network interface 2 years ago
agent.pb.go fd72b134d5 update generated files 2 years ago
agent.proto 1eaea43581 fix protos and "go generate" commands 2 years ago
controller.go 7e4ffa3fa9 Merge pull request #46050 from thaJeztah/libnetwork_remove_interface 1 year ago
default_gateway.go 64c6f72988 libnetwork: remove Network interface 2 years ago
default_gateway_freebsd.go 64c6f72988 libnetwork: remove Network interface 2 years ago
default_gateway_linux.go 64c6f72988 libnetwork: remove Network interface 2 years ago
default_gateway_windows.go 64c6f72988 libnetwork: remove Network interface 2 years ago
drivers_freebsd.go d519bde5da libnet/drivers: stop passing config to drivers... 2 years ago
drivers_ipam.go d478e13639 libnet: un-plumb datastores from IPAM inits 2 years ago
drivers_linux.go d519bde5da libnet/drivers: stop passing config to drivers... 2 years ago
drivers_unsupported.go 1980deffae libn: refactor platform driver registration 2 years ago
drivers_windows.go d519bde5da libnet/drivers: stop passing config to drivers... 2 years ago
endpoint.go 64c6f72988 libnetwork: remove Network interface 2 years ago
endpoint_cnt.go 64c6f72988 libnetwork: remove Network interface 2 years ago
endpoint_info.go c71555f030 libnetwork: return concrete-typed *Endpoint 2 years ago
endpoint_info_unix.go ab35df454d remove pre-go1.17 build-tags 2 years ago
endpoint_info_windows.go ab35df454d remove pre-go1.17 build-tags 2 years ago
endpoint_test.go ab35df454d remove pre-go1.17 build-tags 2 years ago
error.go befff0e13f libnetwork: remove more datastore scope plumbing 2 years ago
errors_test.go be8ff186d6 libnetwork: refactor TestErrorInterfaces into a test 2 years ago
firewall_linux.go 74da6a6363 Switch all logging to use containerd log pkg 2 years ago
firewall_linux_test.go 6025938ee9 Merge pull request #45987 from thaJeztah/cleanup_iptables_the_sequel 2 years ago
firewall_others.go ab35df454d remove pre-go1.17 build-tags 2 years ago
libnetwork_internal_test.go 64c6f72988 libnetwork: remove Network interface 2 years ago
libnetwork_linux_test.go 64c6f72988 libnetwork: remove Network interface 2 years ago
libnetwork_test.go 64c6f72988 libnetwork: remove Network interface 2 years ago
libnetwork_unix_test.go ab35df454d remove pre-go1.17 build-tags 2 years ago
libnetwork_windows_test.go dd5ea7e996 libnetwork: format code with gofumpt 2 years ago
network.go 64c6f72988 libnetwork: remove Network interface 2 years ago
network_unix.go 64c6f72988 libnetwork: remove Network interface 2 years ago
network_windows.go 64c6f72988 libnetwork: remove Network interface 2 years ago
resolver.go 74da6a6363 Switch all logging to use containerd log pkg 2 years ago
resolver_test.go 64c6f72988 libnetwork: remove Network interface 2 years ago
resolver_unix.go 1178319313 libn: fix resolver restore w/ chatty 'iptables -C' 2 years ago
resolver_windows.go ab35df454d remove pre-go1.17 build-tags 2 years ago
sandbox.go dd5ea7e996 libnetwork: format code with gofumpt 2 years ago
sandbox_dns_unix.go 74da6a6363 Switch all logging to use containerd log pkg 2 years ago
sandbox_dns_windows.go ab35df454d remove pre-go1.17 build-tags 2 years ago
sandbox_externalkey_unix.go dd5ea7e996 libnetwork: format code with gofumpt 2 years ago
sandbox_externalkey_unsupported.go ab35df454d remove pre-go1.17 build-tags 2 years ago
sandbox_store.go 64c6f72988 libnetwork: remove Network interface 2 years ago
sandbox_test.go 64c6f72988 libnetwork: remove Network interface 2 years ago
service.go 9e3a6ccf69 libn/i/setmatrix: make generic and constructorless 2 years ago
service_common.go 64c6f72988 libnetwork: remove Network interface 2 years ago
service_common_test.go 64c6f72988 libnetwork: remove Network interface 2 years ago
service_linux.go 64c6f72988 libnetwork: remove Network interface 2 years ago
service_unsupported.go ab35df454d remove pre-go1.17 build-tags 2 years ago
service_windows.go 64c6f72988 libnetwork: remove Network interface 2 years ago
store.go 37cbdeb1f2 libnetwork: remove most of kvstore 1 year ago
store_linux_test.go 02dc5ea720 libnetwork/datastore: remove Store.KVStore() 1 year ago
store_test.go a5ee0d6af8 libnetwork: don't access KVStore directly in tests 1 year ago

README.md

libnetwork - networking for containers

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.

package main

import (
	"fmt"
	"log"

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

func main() {
	// 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("example.com"))
	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.Fatal("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())
}

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.