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

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.