本文整理汇总了Golang中github.com/samalba/dockerclient.Client.StartContainer方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.StartContainer方法的具体用法?Golang Client.StartContainer怎么用?Golang Client.StartContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/samalba/dockerclient.Client
的用法示例。
在下文中一共展示了Client.StartContainer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunDaemon
// RunDaemon creates the docker container, pulling images if necessary, starts
// the container and returns the container information. It does not wait for
// the container to exit.
func RunDaemon(client dockerclient.Client, conf *dockerclient.ContainerConfig, name string) (*dockerclient.ContainerInfo, error) {
// attempts to create the contianer
id, err := client.CreateContainer(conf, name)
if err != nil {
// and pull the image and re-create if that fails
err = client.PullImage(conf.Image, nil)
if err != nil {
return nil, err
}
id, err = client.CreateContainer(conf, name)
if err != nil {
client.RemoveContainer(id, true, true)
return nil, err
}
}
// fetches the container information
info, err := client.InspectContainer(id)
if err != nil {
client.RemoveContainer(id, true, true)
return nil, err
}
// starts the container
err = client.StartContainer(id, &conf.HostConfig)
if err != nil {
client.RemoveContainer(id, true, true)
return nil, err
}
return info, err
}
示例2: Start
// Start a container
func Start(docker dockerclient.Client, id string) string {
// Start the container
hostConfig := &dockerclient.HostConfig{}
err := docker.StartContainer(id, hostConfig)
if err != nil {
log.Fatal(err)
}
return "OK"
}
示例3: Start
func Start(client dockerclient.Client, conf *dockerclient.ContainerConfig, auth *dockerclient.AuthConfig, pull bool) (*dockerclient.ContainerInfo, error) {
// force-pull the image if specified.
if pull {
log.Printf("Pulling image %s", conf.Image)
client.PullImage(conf.Image, auth)
}
// attempts to create the contianer
id, err := client.CreateContainer(conf, "", auth)
if err != nil {
log.Printf("Pulling image %s", conf.Image)
// and pull the image and re-create if that fails
err = client.PullImage(conf.Image, auth)
if err != nil {
log.Errorf("Error pulling %s. %s\n", conf.Image, err)
return nil, err
}
id, err = client.CreateContainer(conf, "", auth)
if err != nil {
log.Errorf("Error creating %s. %s\n", conf.Image, err)
client.RemoveContainer(id, true, true)
return nil, err
}
}
// fetches the container information
info, err := client.InspectContainer(id)
if err != nil {
log.Errorf("Error inspecting %s. %s\n", conf.Image, err)
client.RemoveContainer(id, true, true)
return nil, err
}
// starts the container
err = client.StartContainer(id, &conf.HostConfig)
if err != nil {
log.Errorf("Error starting %s. %s\n", conf.Image, err)
}
return info, err
}