本文整理汇总了Golang中github.com/fsouza/go-dockerclient.Client.StopContainer方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.StopContainer方法的具体用法?Golang Client.StopContainer怎么用?Golang Client.StopContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/fsouza/go-dockerclient.Client
的用法示例。
在下文中一共展示了Client.StopContainer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
fmt.Println("dockerapi started...")
time.Sleep(time.Millisecond * 5000)
fmt.Println("action: " + ACTION)
fmt.Println("containers: " + CONTAINERS)
var containers = strings.Split(CONTAINERS, ",")
var docker *dockerapi.Client
var err error
docker, err = dockerapi.NewClient(DOCKER_HOST)
if err != nil {
fmt.Println(err.Error())
}
err = docker.Ping()
for i := range containers {
fmt.Println(ACTION + " issued for " + containers[i])
switch ACTION {
case "stop":
err = docker.StopContainer(containers[i], 5)
case "start":
err = docker.StartContainer(containers[i], nil)
default:
fmt.Println(ACTION + " unsupported action")
}
if err != nil {
fmt.Println(err.Error())
}
time.Sleep(time.Millisecond * 2000)
}
}
示例2: cleanUp
// cleanUp stops and removes the deployed router
func cleanUp(dockerCli *dockerClient.Client, routerId string) {
dockerCli.StopContainer(routerId, 5)
dockerCli.RemoveContainer(dockerClient.RemoveContainerOptions{
ID: routerId,
Force: true,
})
}
示例3: cleanUp
// cleanUp stops and removes the deployed router
func cleanUp(t *testing.T, dockerCli *dockerClient.Client, routerId string) {
dockerCli.StopContainer(routerId, 5)
if t.Failed() {
dockerCli.Logs(dockerClient.LogsOptions{
Container: routerId,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
Stdout: true,
Stderr: true,
})
}
dockerCli.RemoveContainer(dockerClient.RemoveContainerOptions{
ID: routerId,
Force: true,
})
}
示例4: renameOld
func (c *Container) renameOld(client *dockerClient.Client, opts *dockerClient.CreateContainerOptions) error {
if len(opts.Name) == 0 {
return nil
}
existing, err := inspect(client, opts.Name)
if _, ok := err.(*dockerClient.NoSuchContainer); ok {
return nil
}
if err != nil {
return nil
}
if c.Container != nil && existing.ID == c.Container.ID {
return nil
}
var newName string
if label, ok := existing.Config.Labels[config.HASH]; ok {
newName = fmt.Sprintf("%s-%s", existing.Name, label)
} else {
newName = fmt.Sprintf("%s-unknown-%s", existing.Name, util.RandSeq(12))
}
if existing.State.Running {
err := client.StopContainer(existing.ID, 2)
if err != nil {
return err
}
_, err = client.WaitContainer(existing.ID)
if err != nil {
return err
}
}
log.Debugf("Renaming %s to %s", existing.Name, newName)
return client.RenameContainer(dockerClient.RenameContainerOptions{ID: existing.ID, Name: newName})
}
示例5: StopContainers
// StopContainers stops all the containers in ids slice
func StopContainers(client *docker.Client, ids []string) {
for _, id := range ids {
client.StopContainer(id, 10)
}
}