Rob Murray 964ab7158c Explicitly set MTU on bridge devices. 1 year ago
..
bitmap 564a13285f libnetwork/bitmap: improve documentation 2 years ago
cluster 0f6cb61f2d Switch from x/net/context -> context 7 years ago
cmd cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
config cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
datastore 4af420f978 libnetwork/internal/kvstore: prune unused method 1 year ago
diagnostic cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
discoverapi a08a254df3 libnetwork: drop DatastoreConfig discovery type 2 years ago
docs 9e817251a8 libnetwork/docs: fix broken link 2 years ago
driverapi 42d34e40f9 libnet: Replace BadRequest with InvalidParameter 1 year ago
drivers 964ab7158c Explicitly set MTU on bridge devices. 1 year ago
drvregistry a0a8d9d057 libnetwork: notify another driver registerer 1 year ago
etchosts 1cd937a867 libnetwork/etchosts: format code with gofumpt 2 years ago
internal 4af420f978 libnetwork/internal/kvstore: prune unused method 1 year ago
ipam 7257c77e19 libnetwork/ipam: refactor prefix-overlap checks 1 year ago
ipamapi c22ec82477 libnet: Fix error capitalization 1 year ago
ipams cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
ipamutils bba21735bf libnetwork/ipamutils: format code with gofumpt 2 years ago
ipbits 3c59ef247f libnet/ipam: use netip types internally 2 years ago
iptables cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
netlabel 808120e5b8 New `host_ipv6` bridge option to SNAT IPv6 connections 1 year ago
netutils 492c09276d tests: Move libnetwork/testutils to internal/testutils/netnsutils 1 year ago
networkdb cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
ns cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
options 948f55d0b7 libnetwork/options: remove unused NewGeneric, and use map[string]any 1 year ago
osl cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
portallocator cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
portmapper cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
resolvconf cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
scope 6ec03d6745 libnetwork: move datastore Scope consts to libnetwork/scope 1 year ago
support 4b981436fe Fixup libnetwork lint errors 4 years ago
types bd0111c1f4 libnet: Replace NoServiceError with UnavailableError 1 year 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 adea457841 Merge pull request #46553 from thaJeztah/no_panic 1 year 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 677d41aa3b Plumb context through info endpoint 1 year ago
controller_linux.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
controller_others.go 95abde479a libnetwork: implement Controller.setupOSLSandbox 1 year ago
default_gateway.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
default_gateway_freebsd.go 64c6f72988 libnetwork: remove Network interface 1 year ago
default_gateway_linux.go 64c6f72988 libnetwork: remove Network interface 1 year ago
default_gateway_windows.go 64c6f72988 libnetwork: remove Network interface 1 year ago
drivers_freebsd.go 77c2613d3a libnetwork: fix some missing imports on macOS and FreeBSD 1 year 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 77c2613d3a libnetwork: fix some missing imports on macOS and FreeBSD 1 year ago
drivers_windows.go d519bde5da libnet/drivers: stop passing config to drivers... 2 years ago
endpoint.go 524eef5d75 Merge pull request #46681 from corhere/libn/datastore-misc-cleanups 1 year ago
endpoint_cnt.go 4039b9c9c4 libnetwork/datastore: drop (KVObject).DataScope() 1 year ago
endpoint_info.go 8c6a46f643 libnetwork: Endpoint.AddStaticRoute don't create StaticRoute if unused 1 year 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_unix_test.go c0562d4eed libnetwork: rename unix-only testfiles 1 year ago
error.go 42d34e40f9 libnet: Replace BadRequest with InvalidParameter 1 year ago
errors_test.go 42d34e40f9 libnet: Replace BadRequest with InvalidParameter 1 year ago
firewall_linux.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
firewall_linux_test.go 492c09276d tests: Move libnetwork/testutils to internal/testutils/netnsutils 1 year ago
firewall_others.go 9484520327 libnetwork: arrangeUserFilterRule: don't return early 1 year ago
libnetwork_internal_test.go 4de8459265 libnet: add OTEL tracing to the embedded DNS 1 year ago
libnetwork_linux_test.go 677d41aa3b Plumb context through info endpoint 1 year 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 524eef5d75 Merge pull request #46681 from corhere/libn/datastore-misc-cleanups 1 year ago
network_unix.go 64c6f72988 libnetwork: remove Network interface 1 year ago
network_windows.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
resolver.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
resolver_test.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
resolver_unix.go 1178319313 libn: fix resolver restore w/ chatty 'iptables -C' 2 years ago
resolver_unix_test.go de4ba13400 libnetwork: move resolver tests that were skipped on Windows 1 year ago
resolver_windows.go ab35df454d remove pre-go1.17 build-tags 2 years ago
sandbox.go 0456c0db87 libnetwork: refactor isDistributedControl() 1 year ago
sandbox_dns_unix.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
sandbox_dns_unix_test.go 1e4e9161c5 libnetwork: move TestDNSOptions to a non-windows file 1 year ago
sandbox_dns_windows.go a365fb0e9d libnetwork: move more osl.Sandbox related code to Linux-only files 1 year ago
sandbox_externalkey_unix.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
sandbox_externalkey_unsupported.go ab35df454d remove pre-go1.17 build-tags 2 years ago
sandbox_linux.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
sandbox_options.go 06e540c271 libnetwork: move all SandboxOptions to a separate file 1 year ago
sandbox_store.go f0b89e63b9 Fix missing import for "scope" package 1 year ago
sandbox_unix_test.go 6dba98cf38 libnetwork: implement Controller.GetSandbox(containerID) 1 year ago
sandbox_unsupported.go b92cf68add libnetwork/osl: remove Sandbox and Info interfaces 1 year ago
service.go 9e3a6ccf69 libn/i/setmatrix: make generic and constructorless 2 years ago
service_common.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
service_common_unix_test.go c0562d4eed libnetwork: rename unix-only testfiles 1 year ago
service_linux.go f20abbc96c libnetwork: use conntrack and --ctstate for all rules 1 year ago
service_unsupported.go ab35df454d remove pre-go1.17 build-tags 2 years ago
service_windows.go cff4f20c44 migrate to github.com/containerd/log v0.1.0 1 year ago
store.go 677d41aa3b Plumb context through info endpoint 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.