network

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package network names the networks containers join, as Docker's `network` commands do: "bridge" (the default) and the networks created by `wctr network create` are in-engine networks (netdriver.Local, with DNS by container name on every one of them, "bridge" included); "none" is no network; and drivers registered by the host — a class network through the relay — appear under their own names.

Index

Constants

View Source
const (
	Bridge = "bridge"
	None   = "none"
	Host   = "host"
)

Names the engine reserves.

View Source
const MaxNetworks = 64

MaxNetworks bounds the networks `network create` may make.

Variables

View Source
var (
	// ErrNotFound is a network that does not exist.
	ErrNotFound = errors.New("network: not found")
	// ErrExists is a create of a name in use.
	ErrExists = errors.New("network: already exists")
	// ErrInUse is a remove of a network a container uses.
	ErrInUse = errors.New("network: in use")
	// ErrInvalid is a bad name or an operation a network refuses.
	ErrInvalid = errors.New("network: invalid")
)

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager holds the engine's networks.

func New

func New(opt Options) (*Manager, []string, error)

New returns a manager with "bridge" and "none", the host drivers, and the networks created before (from Store); a damaged record is skipped and reported.

func (*Manager) AddDriver added in v0.11.0

func (m *Manager) AddDriver(name, driverName string, d netdriver.NetworkDriver) (Network, error)

AddDriver adds a host-provided network at run time (a class joined from a page); driverName describes it in `network ls`. RemoveDriver hands it back; Remove refuses it.

func (*Manager) Attach

func (m *Manager) Attach(ctx context.Context, network, name string, aliases []string) (netdriver.Endpoint, error)

Attach puts a container on a network ("" = the default) under its DNS name and its aliases; it is container.Options.Network. A network whose driver has no aliases refuses a container that asks for some.

func (*Manager) Close

func (m *Manager) Close()

Close closes every network.

func (*Manager) Create

func (m *Manager) Create(name string, labels map[string]string) (Network, error)

Create makes an in-engine network on the next free /16 of 10.89.0.0 onwards.

func (*Manager) Default

func (m *Manager) Default() string

Default is the network a container joins when it names none.

func (*Manager) Get

func (m *Manager) Get(ref string) (Network, error)

Get finds a network by name, ID or unique ID prefix.

func (*Manager) List

func (m *Manager) List() []Network

List returns the networks, by name.

func (*Manager) Prune added in v0.14.0

func (m *Manager) Prune(inUse func(name string) bool, keep func(labels map[string]string) bool) []string

Prune removes every created network that no container uses and whose labels match keep (nil: all), and returns their names.

func (*Manager) Remove

func (m *Manager) Remove(ref string, inUse func(name string) bool) error

Remove deletes a created network that no container uses.

func (*Manager) RemoveDriver added in v0.11.0

func (m *Manager) RemoveDriver(name string) (netdriver.NetworkDriver, error)

RemoveDriver takes a network added by AddDriver away and returns its driver (the caller closes it): containers on it keep their sockets until they exit, and a later start of one fails with "network not found".

type Network

type Network struct {
	Name    string
	ID      string
	Driver  string // "bridge" (in-engine), "null", or a host driver's name
	Subnet  string // empty for none and host drivers
	Created time.Time
	Labels  map[string]string
	// Builtin networks cannot be removed.
	Builtin bool
}

Network is what `network ls` and `inspect` show.

type Options

type Options struct {
	// Store keeps created networks across restarts (nil: memory only).
	Store state.Store
	// Drivers are host-provided networks by name (e.g. "class" through the
	// relay). Their names are reserved.
	Drivers map[string]netdriver.NetworkDriver
	// DriverName describes a host driver in `network ls` (default
	// "remote").
	DriverName string
}

Options configures a Manager.

Jump to

Keyboard shortcuts

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