docker

package
v0.0.0-...-4ef74c8 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package docker manages dbctl databases through the Docker Engine API.

Index

Constants

View Source
const ContainerPrefix = "dbctl."

ContainerPrefix prefixes the name of every container managed by dbctl.

Variables

View Source
var (
	ErrNotFound   = errors.New("database not found")
	ErrNotManaged = errors.New("container is not managed by dbctl")
	ErrNotRunning = errors.New("database is not running")
	ErrUnhealthy  = errors.New("database is unhealthy")

	ErrDaemonUnreachable = errors.New("cannot reach the docker daemon")
)

Functions

This section is empty.

Types

type Client

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

Client talks to the Docker daemon on behalf of dbctl.

func New

func New(ctx context.Context, databases *database.Registry) (*Client, error)

New connects to the Docker daemon from the environment and ensures the dbctl network exists.

func (*Client) Backup

func (c *Client) Backup(ctx context.Context, id string, w io.Writer) error

Backup dumps the database to w.

func (*Client) Close

func (c *Client) Close() error

Close releases the connection to the Docker daemon.

func (*Client) Create

func (c *Client) Create(ctx context.Context, opts *CreateOptions) (string, error)

Create creates and starts a database container with its data volume and returns the container ID.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, id string, opts DeleteOptions) ([]string, error)

Delete stops and removes a database container and, unless KeepVolumes is set, its data volumes. It returns the names of the removed volumes.

func (*Client) ImageExists

func (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)

ImageExists reports whether the image is available locally.

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, id string) (*Database, error)

Inspect returns the database with the given short name, container name or ID prefix.

func (*Client) List

func (c *Client) List(ctx context.Context) ([]Database, error)

List returns every database managed by dbctl, including stopped ones.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, id string, opts LogsOptions) error

Logs streams the database logs until they end or ctx is canceled.

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, ref string) error

Pull downloads the image from its registry.

func (*Client) Restart

func (c *Client) Restart(ctx context.Context, id string) error

Restart stops and starts a database.

func (*Client) Restore

func (c *Client) Restore(ctx context.Context, id string, r io.Reader) error

Restore loads a dump read from r into the database.

func (*Client) Shell

func (c *Client) Shell(ctx context.Context, id string, opts ShellOptions) error

Shell opens the database client, or /bin/sh when the template has none or Plain is set.

func (*Client) Start

func (c *Client) Start(ctx context.Context, id string) error

Start starts a stopped database.

func (*Client) Stats

func (c *Client) Stats(ctx context.Context, id string) (Stats, error)

Stats returns a resource usage snapshot of the database container.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context, id string) error

Stop stops a running database, keeping its container and data.

func (*Client) WaitReady

func (c *Client) WaitReady(ctx context.Context, id string) error

WaitReady blocks until the database reports healthy, or is running when it has no healthcheck.

type CreateOptions

type CreateOptions struct {
	Definition *database.Definition
	Image      string
	Name       string
	Password   string
	HostIP     string
	HostPort   int
}

CreateOptions configures a new database container.

type Database

type Database struct {
	Created time.Time
	Labels  map[string]string
	Env     map[string]string
	ID      string
	Name    string
	Image   string
	State   string
	Status  string
	Health  string
	Type    string
	// Password is empty for databases created before dbctl stored it.
	Password string
	Ports    []Port
	Volumes  []Volume
	Running  bool
}

Database is a container managed by dbctl.

type DeleteOptions

type DeleteOptions struct {
	KeepVolumes bool
}

DeleteOptions configures how a database is deleted.

type ExitError

type ExitError struct {
	Code int
}

ExitError reports a non-zero exit code from a command run inside a database container.

func (*ExitError) Error

func (e *ExitError) Error() string

type LogsOptions

type LogsOptions struct {
	Stdout io.Writer
	Stderr io.Writer
	Tail   string
	Follow bool
}

LogsOptions configures where and how database logs are streamed.

type Port

type Port struct {
	HostIP        string
	HostPort      string
	ContainerPort string
}

Port is a container port published on the host.

type ShellOptions

type ShellOptions struct {
	Stdin  *os.File
	Stdout io.Writer
	// Plain opens /bin/sh instead of the database client.
	Plain bool
}

ShellOptions configures an interactive session inside a database container.

type Stats

type Stats struct {
	CPUPercent  float64
	MemoryUsage uint64
	MemoryLimit uint64
}

Stats is a resource usage snapshot of a database container.

func (Stats) MemoryLimitMB

func (s Stats) MemoryLimitMB() float64

MemoryLimitMB returns the memory limit in megabytes.

func (Stats) MemoryUsageMB

func (s Stats) MemoryUsageMB() float64

MemoryUsageMB returns the memory usage in megabytes.

type Volume

type Volume struct {
	Name   string
	Source string
	Target string
}

Volume is a volume mounted into a database container.

Jump to

Keyboard shortcuts

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