docker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NetworkName = "uncloud"
	UserChain   = "DOCKER-USER"
	// 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

This section is empty.

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) 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) 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) 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 Manager

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

func NewManager

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

func (*Manager) EnsureUncloudNetwork

func (m *Manager) EnsureUncloudNetwork(ctx context.Context, subnet netip.Prefix) 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) *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) 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) 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) 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.

Jump to

Keyboard shortcuts

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