docker

package
v1.6.11 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostVolume = "host"
	NFSVolume  = "nfs"
	BindVolume = "bind"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	ContainerClient

	ImageClient

	NetworkClient

	Close() error
}

func NewClient

func NewClient(host string, cfg ClientConfig) (Client, error)

NewClient 创建 Docker 客户端

func NewDockerClient

func NewDockerClient(host string, cfg ClientConfig) (Client, error)

type ClientConfig

type ClientConfig struct {
	DockerConfig *DockerConfig `json:"docker"`
	VolImage     string        `json:"vol_image"`
}

type Container

type Container struct {
	Name        string // only allow letters, numbers, and hyphens
	PullImage   bool
	ImageAuth   *ImageAuth
	Image       string
	Command     []string
	EntryPoint  []string
	Labels      map[string]string
	CPU         float32  // cpu cores
	Memory      float32  // memory in GB
	ShmSize     float32  // shm size in GB
	Ports       []string // ports
	Environment []string // environment variables
	Volumes     []Volume
	Links       []string
	NetworkName string
	HostNetwork bool
	HostIpcMode bool
	Privileged  bool
	Runtime     string
	IsRemove    bool
	Restart     string
	WorkDir     string
	Hosts       []string
	User        string // user to run the container, e.g. "root"

}

type ContainerClient

type ContainerClient interface {
	CreateContainer(ctx context.Context, r Container) (containerID string, err error)
	DeleteContainer(ctx context.Context, containerID string) error
	StartContainer(ctx context.Context, containerID string) error
	StopContainer(ctx context.Context, containerID string) error
	RestartContainer(ctx context.Context, containerID string) error
	LogContainer(ctx context.Context, log ContainerLog) (string, error)
	LogContainerStream(ctx context.Context, log ContainerLog) (chan string, error)
	TerminalContainer(ctx context.Context, tty *ContainerTerminal) (chan []byte, error)
	ExecContainer(ctx context.Context, containerID string, cmd string) ([]byte, error)
	InspectContainer(ctx context.Context, containerID string) (*types.ContainerJSON, error)
	ListContainer(ctx context.Context, opt container.ListOptions) ([]types.Container, error)
	CommitContainer(ctx context.Context, containerID string, imageName string) (string, error)
	InspectImage(ctx context.Context, id string) (types.ImageInspect, error)
}

type ContainerLog

type ContainerLog struct {
	ContainerID string
	Lines       int
	Follow      bool
	Timestamp   bool
}

type ContainerTerminal

type ContainerTerminal struct {
	ContainerID string   `form:"container_id"`
	Cols        int      `form:"cols"`
	Rows        int      `form:"rows"`
	Env         []string `form:"env"`
	Cmd         string   `form:"cmd"`
	Input       chan []byte
}

type DockerClient

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

implement ContainerClient interface

func (*DockerClient) Close

func (d *DockerClient) Close() error

func (*DockerClient) CommitContainer

func (d *DockerClient) CommitContainer(ctx context.Context, containerID, imageName string) (id string, err error)

CommitContainer save container as image

func (*DockerClient) CreateContainer

func (d *DockerClient) CreateContainer(ctx context.Context, r Container) (containerID string, err error)

func (*DockerClient) CreateNetwork

func (d *DockerClient) CreateNetwork(ctx context.Context, name string, options network.CreateOptions) error

func (*DockerClient) DeleteContainer

func (d *DockerClient) DeleteContainer(ctx context.Context, containerID string) error

DeleteContainer delete container

func (*DockerClient) ExecContainer

func (d *DockerClient) ExecContainer(ctx context.Context, containerID string, cmd string) ([]byte, error)

func (*DockerClient) GetNetwork

func (d *DockerClient) GetNetwork(ctx context.Context, name string) error

func (*DockerClient) InspectContainer

func (d *DockerClient) InspectContainer(ctx context.Context, containerID string) (*types.ContainerJSON, error)

func (*DockerClient) InspectImage

func (d *DockerClient) InspectImage(ctx context.Context, id string) (types.ImageInspect, error)

func (*DockerClient) ListContainer

func (d *DockerClient) ListContainer(ctx context.Context, opt container.ListOptions) ([]types.Container, error)

func (*DockerClient) LogContainer

func (d *DockerClient) LogContainer(ctx context.Context, log ContainerLog) (string, error)

func (*DockerClient) LogContainerStream

func (d *DockerClient) LogContainerStream(ctx context.Context, log ContainerLog) (chan string, error)

func (*DockerClient) PullImage

func (d *DockerClient) PullImage(ctx context.Context, imageName string, auth *ImageAuth) error

PullImage pull image

func (*DockerClient) PushImage

func (d *DockerClient) PushImage(ctx context.Context, imageName string, auth *ImageAuth) error

PushImage push image

func (*DockerClient) RestartContainer

func (d *DockerClient) RestartContainer(ctx context.Context, containerID string) error

RestartContainer restart container

func (*DockerClient) StartContainer

func (d *DockerClient) StartContainer(ctx context.Context, containerID string) error

StartContainer start container

func (*DockerClient) StopContainer

func (d *DockerClient) StopContainer(ctx context.Context, containerID string) error

StopContainer stop container

func (*DockerClient) TerminalContainer

func (d *DockerClient) TerminalContainer(ctx context.Context, tty *ContainerTerminal) (chan []byte, error)

type DockerConfig

type DockerConfig struct {
	Socket  string `json:"socket"`
	Port    int    `json:"port"`
	TLS     bool   `json:"tls"`
	TLSCa   string `json:"tls_ca"`
	TLSCert string `json:"tls_cert"`
	TLSKey  string `json:"tls_key"`
}

type ImageAuth

type ImageAuth struct {
	Username string
	Password string
}

type ImageClient

type ImageClient interface {
	PullImage(ctx context.Context, image string, auth *ImageAuth) error
	PushImage(ctx context.Context, image string, auth *ImageAuth) error
}

type NetworkClient

type NetworkClient interface {
	CreateNetwork(ctx context.Context, name string, options network.CreateOptions) error
	GetNetwork(ctx context.Context, name string) error
}

type Volume

type Volume struct {
	Type       string
	Server     string
	Source     string
	Target     string
	ReadOnly   bool
	Shared     bool
	Privileged bool
}

Jump to

Keyboard shortcuts

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