docker

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Image is the name of the image to pull and run.
	Image string
	// Env vars to pass to the docker container.
	Env []string
	// Internal Port to expose anc connect to.
	Port string
	// Out is a custom writer to send docker cli output to.
	Out io.Writer
	// contains filtered or unexported fields
}

Config is used to configure container creation.

func MariaDB

func MariaDB(version string, opts ...ConfigOption) (*Config, error)

MariaDB returns a new Config for a MariaDB image.

func MySQL

func MySQL(version string, opts ...ConfigOption) (*Config, error)

MySQL returns a new Config for a MySQL image.

func NewConfig

func NewConfig(opts ...ConfigOption) (*Config, error)

NewConfig returns a new config with the given options applied.

func PostgreSQL

func PostgreSQL(version string, opts ...ConfigOption) (*Config, error)

PostgreSQL returns a new Config for a PostgreSQL image.

func (*Config) Run

func (c *Config) Run(ctx context.Context) (*Container, error)

Run pulls and starts a new docker container from the Config.

type ConfigOption

type ConfigOption func(*Config) error

ConfigOption allows configuring Config with functional arguments.

func Env

func Env(env ...string) ConfigOption

Env sets the environment variables to pass to the container. For example:

Config(Image("mysql"), Env("MYSQL_ROOT_PASSWORD=password"))
Config(Image("postgres"), Env("MYSQL_ROOT_PASSWORD=password"))

func Image

func Image(i string) ConfigOption

Image sets the docker image to use. For example:

Image("mysql")
Image("postgres:13")

func Out

func Out(w io.Writer) ConfigOption

Out sets an io.Writer to use when running docker commands. For example:

buf := new(bytes.Buffer)
NewConfig(Out(buf))

func Port

func Port(p string) ConfigOption

Port sets the port the container services exposes. For example:

Port("3306")
Port("5432")

type Container

type Container struct {

	// ID of the container.
	ID string
	// Passphrase of the root user.
	Passphrase string
	// Port on the host this containers service is bound to.
	Port string
	// contains filtered or unexported fields
}

A Container is an instance of a created container.

func (*Container) Close

func (c *Container) Close() error

Close stops and removes this container.

func (*Container) URL

func (c *Container) URL() (string, error)

URL returns a URL to connect to the Container.

func (*Container) Wait

func (c *Container) Wait(ctx context.Context, timeout time.Duration) error

Wait waits for this container to be ready.

Jump to

Keyboard shortcuts

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