discovery

package
v20.10.14+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README


page_title: Docker discovery page_description: discovery page_keywords: docker, clustering, discovery

Discovery

Docker comes with multiple Discovery backends.

Backends

Using etcd

Point your Docker Engine instances to a common etcd instance. You can specify the address Docker uses to advertise the node using the --cluster-advertise flag.

$ dockerd -H=<node_ip:2376> --cluster-advertise=<node_ip:2376> --cluster-store etcd://<etcd_ip1>,<etcd_ip2>/<path>

Using consul

Point your Docker Engine instances to a common Consul instance. You can specify the address Docker uses to advertise the node using the --cluster-advertise flag.

$ dockerd -H=<node_ip:2376> --cluster-advertise=<node_ip:2376> --cluster-store consul://<consul_ip>/<path>

Using zookeeper

Point your Docker Engine instances to a common Zookeeper instance. You can specify the address Docker uses to advertise the node using the --cluster-advertise flag.

$ dockerd -H=<node_ip:2376> --cluster-advertise=<node_ip:2376> --cluster-store zk://<zk_addr1>,<zk_addr2>/<path>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSupported is returned when a discovery service is not supported.
	ErrNotSupported = errors.New("discovery service not supported")

	// ErrNotImplemented is returned when discovery feature is not implemented
	// by discovery backend.
	ErrNotImplemented = errors.New("not implemented in this discovery service")
)

Functions

func Generate

func Generate(pattern string) []string

Generate takes care of IP generation

func ParseAdvertise

func ParseAdvertise(advertise string) (string, error)

ParseAdvertise parses the --cluster-advertise daemon config which accepts <ip-address>:<port> or <interface-name>:<port>

func Register

func Register(scheme string, d Backend) error

Register makes a discovery backend available by the provided scheme. If Register is called twice with the same scheme an error is returned.

Types

type Backend

type Backend interface {
	// Watcher must be provided by every backend.
	Watcher

	// Initialize the discovery with URIs, a heartbeat, a ttl and optional settings.
	Initialize(string, time.Duration, time.Duration, map[string]string) error

	// Register to the discovery.
	Register(string) error
}

Backend is implemented by discovery backends which manage cluster entries.

func New

func New(rawurl string, heartbeat time.Duration, ttl time.Duration, clusterOpts map[string]string) (Backend, error)

New returns a new Discovery given a URL, heartbeat and ttl settings. Returns an error if the URL scheme is not supported.

type Entries

type Entries []*Entry

Entries is a list of *Entry with some helpers.

func CreateEntries

func CreateEntries(addrs []string) (Entries, error)

CreateEntries returns an array of entries based on the given addresses.

func (Entries) Contains

func (e Entries) Contains(entry *Entry) bool

Contains returns true if the Entries contain a given Entry.

func (Entries) Diff

func (e Entries) Diff(cmp Entries) (Entries, Entries)

Diff compares two entries and returns the added and removed entries.

func (Entries) Equals

func (e Entries) Equals(cmp Entries) bool

Equals returns true if cmp contains the same data.

type Entry

type Entry struct {
	Host string
	Port string
}

An Entry represents a host.

func NewEntry

func NewEntry(url string) (*Entry, error)

NewEntry creates a new entry.

func (*Entry) Equals

func (e *Entry) Equals(cmp *Entry) bool

Equals returns true if cmp contains the same data.

func (*Entry) String

func (e *Entry) String() string

String returns the string form of an entry.

type Watcher

type Watcher interface {
	// Watch the discovery for entry changes.
	// Returns a channel that will receive changes or an error.
	// Providing a non-nil stopCh can be used to stop watching.
	Watch(stopCh <-chan struct{}) (<-chan Entries, <-chan error)
}

Watcher provides watching over a cluster for nodes joining and leaving.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL