dockerop

package module
v0.0.0-...-a8d7b6c Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

dockerop

Docker client based on sdk, written in Go.

interface

// DockerOp interface of dockerop
type DockerOp interface {
	// client basic function:
	// NewOpClient create a new client of docker engine
	Close() error // close
	Ping(ctx context.Context) (types.Ping, error)
	Info(ctx context.Context) (types.Info, error)
	RegistryLogin(ctx context.Context, auth types.AuthConfig) error
	// client image function:
	ImageList(ctx context.Context) ([]types.ImageSummary, error)
	ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (string, error)
	ImageRemove(ctx context.Context, imageID string) error
	ImagesPrune(ctx context.Context) error
	// client container function:
	ContainerList(ctx context.Context) ([]types.Container, error)
	ContainerCreate(ctx context.Context, def *ContainerDef) (string, error)
	ContainerStart(ctx context.Context, containerID string) error
	ContainerPause(ctx context.Context, containerID string) error
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
	ContainerRemove(ctx context.Context, containerID string) error
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
	ContainerLogs(ctx context.Context, containerID string) (string, error)
	ContainerExec(ctx context.Context, containerID string, cmd []string) (string, error)
	//ContainersPrune(ctx context.Context) error
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerDef

type ContainerDef struct {
	Image   string
	CName   string
	Cmd     strslice.StrSlice
	PortSet nat.PortSet   // 容器开放端口 List of exposed ports
	PortMap nat.PortMap   // 容器与主机端口映射 Port mapping between the exposed port (container) and the host
	Mounts  []mount.Mount // 挂载目录
}

type DockerOp

type DockerOp interface {
	// client basic function:
	// NewOpClient create a new client of docker engine
	Close() error // close
	Ping(ctx context.Context) (types.Ping, error)
	Info(ctx context.Context) (types.Info, error)
	RegistryLogin(ctx context.Context, auth types.AuthConfig) error
	// client image function:
	ImageList(ctx context.Context) ([]types.ImageSummary, error)
	ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (string, error)
	ImageRemove(ctx context.Context, imageID string) error
	ImagesPrune(ctx context.Context) error
	// client container function:
	ContainerList(ctx context.Context) ([]types.Container, error)
	ContainerCreate(ctx context.Context, def *ContainerDef) (string, error)
	ContainerStart(ctx context.Context, containerID string) error
	ContainerPause(ctx context.Context, containerID string) error
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
	ContainerRemove(ctx context.Context, containerID string) error
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
	ContainerLogs(ctx context.Context, containerID string) (string, error)
	ContainerExec(ctx context.Context, containerID string, cmd []string) (string, error)
}

DockerOp interface of dockerop

type OpClient

type OpClient struct {

	// others
	Auth          types.AuthConfig
	Time          time.Time // set in RegistryLogin
	IdentityToken string    // returned in RegistryLogin
	Status        string    // returned in RegistryLogin
	// contains filtered or unexported fields
}

OpClient the client operating docker engine

func NewOpClient

func NewOpClient(host string, httpcli *http.Client) (*OpClient, error)

NewOpClient return a pointer to OpClient

func (*OpClient) Close

func (c *OpClient) Close() error

Close close the connection to docker engine

func (*OpClient) ContainerCreate

func (c *OpClient) ContainerCreate(ctx context.Context, def *ContainerDef) (string, error)

ContainerCreate create a container

func (*OpClient) ContainerExec

func (c *OpClient) ContainerExec(ctx context.Context, containerID string, cmd []string) (string, error)

ContainerExec exec cmds in remote docker and return stdout/stderr cmd such as : []string{"ls", "-al"},

func (*OpClient) ContainerInspect

func (c *OpClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)

ContainerInspect pause the container

func (*OpClient) ContainerList

func (c *OpClient) ContainerList(ctx context.Context) ([]types.Container, error)

ContainerList return all of the containers

func (*OpClient) ContainerLogs

func (c *OpClient) ContainerLogs(ctx context.Context, containerID string) (string, error)

ContainerLogs return the logs in container

func (*OpClient) ContainerPause

func (c *OpClient) ContainerPause(ctx context.Context, containerID string) error

ContainerPause pause the container

func (*OpClient) ContainerRemove

func (c *OpClient) ContainerRemove(ctx context.Context, containerID string) error

ContainerRemove remove the container

func (*OpClient) ContainerStart

func (c *OpClient) ContainerStart(ctx context.Context, containerID string) error

ContainerStart start the container

func (*OpClient) ContainerStop

func (c *OpClient) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error

ContainerStop stops a container. In case the container fails to stop gracefully within a time frame specified by the timeout argument, it is forcefully terminated (killed). If the timeout is nil, the container's StopTimeout value is used, if set, otherwise the engine default. A negative timeout value can be specified, meaning no timeout, i.e. no forceful termination is performed.

func (*OpClient) ImageList

func (c *OpClient) ImageList(ctx context.Context) ([]types.ImageSummary, error)

ImageList list all the images

func (*OpClient) ImagePull

func (c *OpClient) ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (string, error)

ImagePull pull the image, options has the cred of registry. ref such as "docker.io/library/nginx:latest" return `docker pull stdout information` and `error`

func (*OpClient) ImageRemove

func (c *OpClient) ImageRemove(ctx context.Context, imageID string) error

ImageRemove remove the image

func (*OpClient) ImagesPrune

func (c *OpClient) ImagesPrune(ctx context.Context) error

ImagesPrune prune the image

func (*OpClient) Info

func (c *OpClient) Info(ctx context.Context) (types.Info, error)

Info returns the information about the docker engine

func (*OpClient) Ping

func (c *OpClient) Ping(ctx context.Context) (types.Ping, error)

Ping pings the server

func (*OpClient) RegistryLogin

func (c *OpClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) error

RegistryLogin authenticates the docker server with a given docker registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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