docker.io/libnetwork
luoyaoming 55742535ba Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
..
.circleci Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
api Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
bitseq Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
client Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
cluster Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
cmd Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
config Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
datastore Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
diagnostic Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
discoverapi Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
docs Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
driverapi Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
drivers Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
drvregistry Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
etchosts Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
hostdiscovery Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
idm Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
internal Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
ipam Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
ipamapi Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
ipams Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
ipamutils Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
iptables Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
netlabel Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
netutils Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
networkdb Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
ns Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
options Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
osl Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
portallocator Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
portmapper Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
resolvconf Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
support Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
test/integration Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
testutils Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
types Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
vendor/github.com Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
.dockerignore Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
CHANGELOG.md Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
Dockerfile Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
LICENSE Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
MAINTAINERS Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
Makefile Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
README.md Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
Vagrantfile Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
agent.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
agent.pb.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
agent.proto Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
controller.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
default_gateway.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
default_gateway_freebsd.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
default_gateway_linux.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
default_gateway_windows.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
drivers_freebsd.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
drivers_ipam.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
drivers_linux.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
drivers_windows.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
endpoint.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
endpoint_cnt.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
endpoint_info.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
endpoint_info_unix.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
endpoint_info_windows.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
endpoint_test.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
error.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
errors_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
firewall_linux.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
firewall_others.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
firewall_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
libnetwork_internal_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
libnetwork_linux_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
libnetwork_test.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
machines Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
network.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
network_unix.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
network_windows.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
resolver.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
resolver_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
resolver_unix.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
resolver_windows.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
sandbox.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
sandbox_dns_unix.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
sandbox_dns_windows.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
sandbox_externalkey.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
sandbox_externalkey_unix.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
sandbox_externalkey_windows.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
sandbox_store.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
sandbox_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
service.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
service_common.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
service_common_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
service_linux.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
service_unsupported.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
service_windows.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
store.go Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00
store_linux_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
store_test.go Import Upstream version 20.10.16 2022-12-16 13:24:03 +08:00
vendor.conf Import Upstream version 20.10.25+dfsg1 2024-04-24 10:03:53 +08:00

README.md

Warning libnetwork was moved to https://github.com/moby/moby/tree/master/libnetwork

libnetwork has been merged to the main repo of Moby since Docker 22.06.

The old libnetwork repo (https://github.com/moby/libnetwork) now only accepts PR for Docker 20.10, and will be archived after the EOL of Docker 20.10.


libnetwork - networking for containers

Circle CI Coverage Status GoDoc Go Report Card

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.

import (
	"fmt"
	"log"

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

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())
}

Contributing

Want to hack on libnetwork? Docker's contributions guidelines apply.

Code and documentation copyright 2015 Docker, inc. Code released under the Apache 2.0 license. Docs released under Creative commons.