Documentation ¶
Overview ¶
Package meli provides programming interface to interact with the docker daemon. meli also has a command line application(cli) that is a faster and drop in alternative to docker-compose. The installation instructions for the cli application can be found: https://github.com/komuw/meli#installingupgrading
Example usage:
package main import ( "errors" "github.com/sanity-io/litter" "github.com/gogo/protobuf/vanity/command" "context" "log" "os" "github.com/docker/docker/client" "github.com/komuw/meli" ) func main() { dc := &meli.DockerContainer{ ComposeService: meli.ComposeService{Image: "busybox"}, LogMedium: os.Stdout, FollowLogs: true} ctx := context.Background() cli, err := client.NewEnvClient() if err != nil { log.Fatal(err, " :unable to intialize docker client") } defer cli.Close() meli.LoadAuth() // read dockerhub info err = meli.PullDockerImage(ctx, cli, dc) log.Println(err) }
Index ¶
- Variables
- func BuildDockerImage(ctx context.Context, cli APIclient, dc *DockerContainer) (string, error)
- func ConnectNetwork(ctx context.Context, cli APIclient, dc *DockerContainer) error
- func ContainerLogs(ctx context.Context, cli APIclient, dc *DockerContainer) error
- func ContainerStart(ctx context.Context, cli APIclient, dc *DockerContainer) error
- func CreateContainer(ctx context.Context, cli APIclient, dc *DockerContainer) (bool, string, error)
- func CreateDockerVolume(ctx context.Context, cli APIclient, name, driver string, dst io.Writer) (string, error)
- func GetNetwork(ctx context.Context, networkName string, cli APIclient) (string, error)
- func LoadAuth()
- func PullDockerImage(ctx context.Context, cli APIclient, dc *DockerContainer) error
- type APIclient
- type Buildstruct
- type ComposeService
- type DockerComposeConfig
- type DockerContainer
Constants ¶
This section is empty.
Variables ¶
var AuthInfo sync.Map
AuthInfo stores a users' docker registry/hub info
Functions ¶
func BuildDockerImage ¶
BuildDockerImage builds a docker image via docker daemon
func ConnectNetwork ¶
func ConnectNetwork(ctx context.Context, cli APIclient, dc *DockerContainer) error
ConnectNetwork connects a container to an existent docker network.
func ContainerLogs ¶
func ContainerLogs(ctx context.Context, cli APIclient, dc *DockerContainer) error
ContainerLogs returns the logs generated by a container in an io.ReadCloser.
func ContainerStart ¶
func ContainerStart(ctx context.Context, cli APIclient, dc *DockerContainer) error
ContainerStart starts a docker container via docker daemon server
func CreateContainer ¶
CreateContainer creates a docker container
func CreateDockerVolume ¶
func CreateDockerVolume(ctx context.Context, cli APIclient, name, driver string, dst io.Writer) (string, error)
CreateDockerVolume creates a docker volume
func GetNetwork ¶
GetNetwork gets or creates newtwork(if it doesn't exist yet.)
func PullDockerImage ¶
func PullDockerImage(ctx context.Context, cli APIclient, dc *DockerContainer) error
PullDockerImage pulls a docker from a registry via docker daemon
Types ¶
type APIclient ¶
type APIclient interface { // we implement this interface so that we can be able to mock it in tests // https://medium.com/@zach_4342/dependency-injection-in-golang-e587c69478a8 ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (types.Volume, error) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error }
APIclient is meli's client to interact with the docker daemon server
type Buildstruct ¶
type Buildstruct struct { // remember to use caps so that they can be exported Context string `yaml:"context,omitempty"` Dockerfile string `yaml:"dockerfile,omitempty"` }
Buildstruct represents a docker-compose' build section
type ComposeService ¶
type ComposeService struct { Image string `yaml:"image,omitempty"` Ports []string `yaml:"ports,omitempty"` Labels []string `yaml:"labels,omitempty"` Environment []string `yaml:"environment,omitempty"` Command string `yaml:"command,flow,omitempty"` Restart string `yaml:"restart,omitempty"` Build Buildstruct `yaml:"build,omitempty"` Volumes []string `yaml:"volumes,omitempty"` Links []string `yaml:"links,omitempty"` EnvFile []string `yaml:"env_file,omitempty"` }
ComposeService represents a docker-compose' service section
type DockerComposeConfig ¶
type DockerComposeConfig struct { Version string `yaml:"version,omitempty"` Services map[string]ComposeService `yaml:"services"` Volumes map[string]string `yaml:"volumes,omitempty"` }
DockerComposeConfig represents a docker-compose file
type DockerContainer ¶
type DockerContainer struct { ServiceName string ComposeService ComposeService NetworkID string NetworkName string FollowLogs bool DockerComposeFile string ContainerID string // this assumes that there can only be one container per docker-compose service LogMedium io.Writer CurentDir string Rebuild bool EnvFile []string }
DockerContainer represents a docker container
func (*DockerContainer) UpdateContainerID ¶
func (dc *DockerContainer) UpdateContainerID(containerID string)
UpdateContainerID updates a containers ID