docker

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NetworkName = "uncloud"
	// EventsDebounceInterval defines how long to wait before processing the next Docker event. Multiple events
	// occurring within this window will be processed together as a single event to prevent system overload.
	EventsDebounceInterval = 100 * time.Millisecond
	// SyncInterval defines a regular interval to sync containers to the cluster store.
	SyncInterval = 30 * time.Second
)

Variables

This section is empty.

Functions

func ToDockerMounts added in v0.6.0

func ToDockerMounts(volumes []api.VolumeSpec, mounts []api.VolumeMount) ([]mount.Mount, error)

Types

type Client

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

Client is a gRPC client for the Docker service that provides a similar interface to the Docker HTTP client.

func NewClient

func NewClient(conn *grpc.ClientConn) *Client

NewClient creates a new Docker gRPC client with the provided gRPC connection.

func (*Client) Close

func (c *Client) Close() error

Close closes the gRPC connection.

func (*Client) CreateContainer

func (c *Client) CreateContainer(
	ctx context.Context,
	config *container.Config,
	hostConfig *container.HostConfig,
	networkingConfig *network.NetworkingConfig,
	platform *ocispec.Platform,
	name string,
) (container.CreateResponse, error)

CreateContainer creates a new container based on the given configuration.

func (*Client) CreateServiceContainer

func (c *Client) CreateServiceContainer(
	ctx context.Context, serviceID string, spec api.ServiceSpec, containerName string,
) (container.CreateResponse, error)

CreateServiceContainer creates a new container for the service with the given specifications.

func (*Client) CreateVolume added in v0.6.0

func (c *Client) CreateVolume(ctx context.Context, opts volume.CreateOptions) (volume.Volume, error)

CreateVolume creates a new volume with the given options.

func (*Client) InspectContainer

func (c *Client) InspectContainer(ctx context.Context, id string) (types.ContainerJSON, error)

InspectContainer returns the container information for the given container ID.

func (*Client) InspectImage

func (c *Client) InspectImage(ctx context.Context, id string) ([]api.MachineImage, error)

InspectImage returns the image information for the given image ID. The request may be sent to multiple machines.

func (*Client) InspectRemoteImage

func (c *Client) InspectRemoteImage(ctx context.Context, id string) ([]api.MachineRemoteImage, error)

InspectRemoteImage returns the image metadata for an image in a remote registry using the machine's Docker auth credentials if necessary. If the response from a machine doesn't contain an error, the api.RemoteImage will either contain an IndexManifest or an ImageManifest.

func (*Client) InspectServiceContainer

func (c *Client) InspectServiceContainer(ctx context.Context, id string) (api.ServiceContainer, error)

InspectServiceContainer returns the container information and service specification that was used to create the container with the given ID.

func (*Client) ListContainers

func (c *Client) ListContainers(ctx context.Context, opts container.ListOptions) ([]MachineContainers, error)

func (*Client) ListServiceContainers

func (c *Client) ListServiceContainers(
	ctx context.Context, serviceNameOrID string, opts container.ListOptions,
) ([]MachineServiceContainers, error)

ListServiceContainers returns all containers on requested machines that belong to the service with the given name or ID. If serviceNameOrID is empty, all service containers are returned.

func (*Client) ListVolumes added in v0.6.0

func (c *Client) ListVolumes(ctx context.Context, opts volume.ListOptions) ([]MachineVolumes, error)

ListVolumes returns a list of all volumes matching the filter.

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, image string) (<-chan PullImageMessage, error)

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, id string, opts container.RemoveOptions) error

RemoveContainer stops (kills after grace period) and removes a container with the given ID.

func (*Client) RemoveServiceContainer

func (c *Client) RemoveServiceContainer(ctx context.Context, id string, opts container.RemoveOptions) error

RemoveServiceContainer stops (kills after grace period) and removes a service container with the given ID. A service container is a container that has been created with CreateServiceContainer.

func (*Client) RemoveVolume added in v0.6.0

func (c *Client) RemoveVolume(ctx context.Context, id string, force bool) error

RemoveVolume removes a volume with the given ID.

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, id string, opts container.StartOptions) error

StartContainer starts a container with the given ID and options.

func (*Client) StopContainer

func (c *Client) StopContainer(ctx context.Context, id string, opts container.StopOptions) error

StopContainer stops a container with the given ID and options.

type MachineContainers

type MachineContainers struct {
	Metadata   *pb.Metadata
	Containers []types.ContainerJSON
}

type MachineServiceContainers

type MachineServiceContainers struct {
	Metadata   *pb.Metadata
	Containers []api.ServiceContainer
}

type MachineVolumes added in v0.6.0

type MachineVolumes struct {
	Metadata *pb.Metadata
	Response volume.ListResponse
}

MachineVolumes represents a volume list response from a machine.

type Manager

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

func NewManager

func NewManager(client *client.Client, machineID string, store *store.Store) *Manager

func (*Manager) Cleanup added in v0.10.0

func (m *Manager) Cleanup() error

Cleanup removes all uncloud-managed containers and the uncloud Docker network.

func (*Manager) EnsureUncloudNetwork

func (m *Manager) EnsureUncloudNetwork(ctx context.Context, subnet netip.Prefix, dnsServer netip.Addr) error

EnsureUncloudNetwork creates the Docker bridge network NetworkName with the provided machine subnet if it doesn't exist. If the network exists but has a different subnet, it removes and recreates the network. It also configures iptables to allow container access from the WireGuard network.

func (*Manager) WaitDaemonReady

func (m *Manager) WaitDaemonReady(ctx context.Context) error

WaitDaemonReady waits for the Docker daemon to start and be ready to serve requests.

func (*Manager) WatchAndSyncContainers

func (m *Manager) WatchAndSyncContainers(ctx context.Context) error

type PullImageMessage

type PullImageMessage struct {
	Message jsonmessage.JSONMessage
	Err     error
}

type Server

type Server struct {
	pb.UnimplementedDockerServer
	// contains filtered or unexported fields
}

Server implements the gRPC Docker service that proxies requests to the Docker daemon.

func NewServer

func NewServer(cli *client.Client, db *sqlx.DB, internalDNSIP func() netip.Addr, opts ...ServerOption) *Server

NewServer creates a new Docker gRPC server with the provided Docker client.

func (*Server) CreateContainer

func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (*pb.CreateContainerResponse, error)

CreateContainer creates a new container based on the given configuration.

func (*Server) CreateServiceContainer

func (s *Server) CreateServiceContainer(
	ctx context.Context, req *pb.CreateServiceContainerRequest,
) (*pb.CreateContainerResponse, error)

CreateServiceContainer creates a new container for the service with the given specifications.

func (*Server) CreateVolume added in v0.6.0

func (s *Server) CreateVolume(ctx context.Context, req *pb.CreateVolumeRequest) (*pb.CreateVolumeResponse, error)

CreateVolume creates a new volume with the given options.

func (*Server) InspectContainer

func (s *Server) InspectContainer(ctx context.Context, req *pb.InspectContainerRequest) (*pb.InspectContainerResponse, error)

InspectContainer returns the container information for the given container ID.

func (*Server) InspectImage

func (s *Server) InspectImage(ctx context.Context, req *pb.InspectImageRequest) (*pb.InspectImageResponse, error)

InspectImage returns the image information for the given image ID.

func (*Server) InspectRemoteImage

func (s *Server) InspectRemoteImage(
	_ context.Context, req *pb.InspectRemoteImageRequest,
) (*pb.InspectRemoteImageResponse, error)

InspectRemoteImage returns the image metadata for an image in a remote registry using the machine's Docker auth credentials if necessary.

func (*Server) InspectServiceContainer

func (s *Server) InspectServiceContainer(
	ctx context.Context, req *pb.InspectContainerRequest,
) (*pb.ServiceContainer, error)

InspectServiceContainer returns the container information and service specification that was used to create the container with the given ID.

func (*Server) ListContainers

func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error)

func (*Server) ListServiceContainers

func (s *Server) ListServiceContainers(
	ctx context.Context, req *pb.ListServiceContainersRequest,
) (*pb.ListServiceContainersResponse, error)

ListServiceContainers returns all containers that belong to the service with the given name or ID. If req.ServiceId is empty, all service containers are returned.

func (*Server) ListVolumes added in v0.6.0

func (s *Server) ListVolumes(ctx context.Context, req *pb.ListVolumesRequest) (*pb.ListVolumesResponse, error)

ListVolumes returns a list of all volumes matching the filter.

func (*Server) PullImage

func (*Server) RemoveContainer

func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*emptypb.Empty, error)

RemoveContainer stops (kills after grace period) and removes a container with the given ID.

func (*Server) RemoveServiceContainer

func (s *Server) RemoveServiceContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*emptypb.Empty, error)

RemoveServiceContainer stops (kills after grace period) and removes a service container with the given ID. The difference between this method and RemoveContainer is that it also removes the container from the machine database.

func (*Server) RemoveVolume added in v0.6.0

func (s *Server) RemoveVolume(ctx context.Context, req *pb.RemoveVolumeRequest) (*emptypb.Empty, error)

RemoveVolume removes a volume with the given ID.

func (*Server) StartContainer

func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*emptypb.Empty, error)

StartContainer starts a container with the given ID and options.

func (*Server) StopContainer

func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*emptypb.Empty, error)

StopContainer stops a container with the given ID and options.

type ServerOption added in v0.10.0

type ServerOption func(*Server)

ServerOption configures the Docker server.

func WithNetworkReady added in v0.10.0

func WithNetworkReady(networkReady func() bool) ServerOption

WithNetworkReady sets the network readiness check function.

func WithWaitForNetworkReady added in v0.10.0

func WithWaitForNetworkReady(waitForNetworkReady func(ctx context.Context) error) ServerOption

WithWaitForNetworkReady sets the network readiness wait function.

Jump to

Keyboard shortcuts

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