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

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.