docker

package
v0.0.0-...-3a98d3a Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package docker provide abstaraction to pull/start/stop/remove docker image. Package uses docker-cli from running host.

Index

Constants

View Source
const (
	// Default fallback docket tag.
	DefaultImageTag = "stable"

	RETRYNUM = 2
)

Variables

View Source
var (
	LogPullTime     = logPullTime
	LogRunTime      = logRunTime
	LogStatus       = logStatus
	LogPullTimeProd = logPullTimeProd
	LogRunTimeProd  = logRunTimeProd
	LogStatusProd   = logStatusProd
)

Export metrics API.

Functions

func CreateImageName

func CreateImageName(repoPath, tag string) string

CreateImageName creates docker image name from repo-path and tag.

func CreateImageNameFromInputInfo

func CreateImageNameFromInputInfo(di *api.DutInput_DockerImage, defaultRepoPath, defaultTag string) string

CreateImageNameFromInputInfo creates docker image name from input info.

If info is empty then return empty name. If one of the fields empty then use related default value.

func CreateNetwork

func CreateNetwork(ctx context.Context, name string) error

CreateNetwork created network for docker.

func GCloudToken

func GCloudToken(ctx context.Context, keyfile string, forceNewAuth bool) (string, error)

GCloudToken will try to return the gcloud token for `docker login`.

func RemoveNetwork

func RemoveNetwork(ctx context.Context, name string) error

RemoveNetwork removes network from docker.

Types

type Docker

type Docker struct {
	// Requested docker image, if not exist then use FallbackImageName.
	RequestedImageName string
	// Registry to auth for docker interactions.
	Registry string
	// token to token
	TokenFile string
	// Fall back docker image name. Used if RequestedImageName is empty or image not found.
	FallbackImageName string
	// ServicePort tells which port need to bing bind from docker to the host.
	// Bind is always to the first free port.
	ServicePort int
	// Run container in detach mode.
	Detach bool
	// Name to be assigned to the container - should be unique.
	Name string
	// ExecCommand tells if we need run special command when we start container.
	ExecCommand []string
	// Attach volumes to the docker image.
	Volumes []string
	// PortMappings is a list of "host port:docker port" or "docker port" to publish.
	PortMappings []string

	// Network used for running container.
	Network string

	// LogFileDir used for the logfile for the service in the container.
	LogFileDir string

	Stdoutbuf    *bytes.Buffer
	Stderrbuf    *bytes.Buffer
	PullExitCode int
	Started      bool
	// contains filtered or unexported fields
}

Docker holds data to perform the docker manipulations.

func (*Docker) Auth

func (d *Docker) Auth(ctx context.Context) (err error)

Auth with docker registry so that pulling and stuff works.

func (*Docker) MatchingHostPort

func (d *Docker) MatchingHostPort(ctx context.Context, dockerPort string) (string, error)

HostPort returns the port which the given docker port maps to.

func (*Docker) Remove

func (d *Docker) Remove(ctx context.Context) error

Remove removes the containers with matched name.

func (*Docker) Run

func (d *Docker) Run(ctx context.Context, block bool, netbind bool, service string) error

Run docker image. The step will create container and start server inside or execution CLI.

Jump to

Keyboard shortcuts

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