docker

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package docker implements the Docker network driver API and watches Docker events for container starts and stops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WatchEvents

func WatchEvents(
	ctx context.Context,
	cli dockerAPI,
	cache *ContainerCache,
	ownsNetwork func(id string) bool,
	onInfo ContainerInfoCallback,
	onStop ContainerStopCallback,
	onBridgeNetwork func(),
)

WatchEvents watches Docker events and caches container info. When container info is stored, the callback is invoked to trigger Tailscale setup. The context controls the lifecycle - when cancelled, the watcher stops. ownsNetwork reports whether a network ID belongs to this driver. onStop, if set, is called when a container is sent its stop signal. onBridgeNetwork, if set, is called when a bridge network is created.

Types

type ContainerCache

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

ContainerCache caches container info for quick lookup during Join().

func NewContainerCache

func NewContainerCache() *ContainerCache

NewContainerCache creates a new container cache.

func (*ContainerCache) Container added in v0.3.0

func (c *ContainerCache) Container(containerID string) ([]string, string)

Container returns the endpoints the cache holds the container's info for, and its stop signal.

func (*ContainerCache) Delete

func (c *ContainerCache) Delete(endpointID string)

Delete removes container info by endpoint ID.

func (*ContainerCache) GetByEndpoint

func (c *ContainerCache) GetByEndpoint(endpointID string) (*core.ContainerInfo, bool)

GetByEndpoint retrieves container info by endpoint ID.

func (*ContainerCache) Store

func (c *ContainerCache) Store(endpointID string, info *core.ContainerInfo)

Store stores container info keyed by endpoint ID.

type ContainerInfoCallback

type ContainerInfoCallback func(endpointID string, info *core.ContainerInfo)

ContainerInfoCallback is called when container info is stored in the cache. The driver uses this to trigger Tailscale setup.

type ContainerStopCallback

type ContainerStopCallback func(containerID string, endpointIDs []string)

ContainerStopCallback is called when Docker sends a container on this driver's networks its stop signal, before the container exits, with the container's endpoints on them.

type Driver

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

Driver implements the Docker network plugin interface.

func NewDriver

func NewDriver() (*Driver, error)

NewDriver creates a new Docker network driver.

func (*Driver) AllocateNetwork

AllocateNetwork is called during network creation (for multi-host networks).

func (*Driver) CreateEndpoint

CreateEndpoint creates a new endpoint for a container.

func (*Driver) CreateNetwork

func (d *Driver) CreateNetwork(req *network.CreateNetworkRequest) error

CreateNetwork creates a new network.

func (*Driver) DeleteEndpoint

func (d *Driver) DeleteEndpoint(req *network.DeleteEndpointRequest) error

DeleteEndpoint deletes an endpoint.

func (*Driver) DeleteNetwork

func (d *Driver) DeleteNetwork(req *network.DeleteNetworkRequest) error

DeleteNetwork deletes a network.

func (*Driver) DiscoverDelete

func (d *Driver) DiscoverDelete(req *network.DiscoveryNotification) error

DiscoverDelete is called when a node is removed.

func (*Driver) DiscoverNew

func (d *Driver) DiscoverNew(req *network.DiscoveryNotification) error

DiscoverNew is called when a new node is discovered.

func (*Driver) EndpointInfo

func (d *Driver) EndpointInfo(req *network.InfoRequest) (*network.InfoResponse, error)

EndpointInfo returns information about an endpoint.

func (*Driver) FreeNetwork

func (d *Driver) FreeNetwork(req *network.FreeNetworkRequest) error

FreeNetwork is called during network deletion (for multi-host networks).

func (*Driver) GetCapabilities

func (d *Driver) GetCapabilities() (*network.CapabilitiesResponse, error)

GetCapabilities returns the capabilities of the driver.

func (*Driver) Join

func (d *Driver) Join(req *network.JoinRequest) (*network.JoinResponse, error)

Join is called when a container joins the network. It sets up basic networking and returns quickly. Tailscale setup is triggered asynchronously by the Docker event handler.

func (*Driver) Leave

func (d *Driver) Leave(req *network.LeaveRequest) error

Leave is called when a container leaves the network.

func (*Driver) ProgramExternalConnectivity

func (d *Driver) ProgramExternalConnectivity(
	req *network.ProgramExternalConnectivityRequest,
) error

ProgramExternalConnectivity is called to program external connectivity.

func (*Driver) RecoverEndpoints

func (d *Driver) RecoverEndpoints(ctx context.Context) error

RecoverEndpoints scans Docker for containers on tslink networks that are missing from the driver's in-memory state. This handles host reboot and plugin restart. It also starts Tailscale for endpoints that joined but missed their connect event, as when the event stream was down.

func (*Driver) RevokeExternalConnectivity

func (d *Driver) RevokeExternalConnectivity(req *network.RevokeExternalConnectivityRequest) error

RevokeExternalConnectivity is called to revoke external connectivity.

func (*Driver) Shutdown

func (d *Driver) Shutdown(ctx context.Context) error

Shutdown gracefully stops the driver and all managed resources. It cancels the context (stopping the event watcher and any pending operations), stops all endpoints, and waits for goroutines to finish. The passed context controls how long to wait for graceful shutdown.

Jump to

Keyboard shortcuts

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