本文整理匯總了Golang中github.com/docker/engine-api/client.Client.ContainerRemove方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.ContainerRemove方法的具體用法?Golang Client.ContainerRemove怎麽用?Golang Client.ContainerRemove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/engine-api/client.Client
的用法示例。
在下文中一共展示了Client.ContainerRemove方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runContainerCmd
// runs a command in a container , with volume mounted
// returns completion code.
// exits (t.Fatal() or create/start/wait errors
func runContainerCmd(t *testing.T, client *client.Client, volumeName string,
image string, cmd *strslice.StrSlice, addr string) int {
mountPoint := getMountpoint(volumeName)
bind := volumeName + ":" + mountPoint
t.Logf("Running cmd=%v with vol=%s on client %s", cmd, volumeName, addr)
r, err := client.ContainerCreate(context.Background(),
&container.Config{Image: image, Cmd: *cmd,
Volumes: map[string]struct{}{mountPoint: {}}},
&container.HostConfig{Binds: []string{bind}}, nil, "")
if err != nil {
t.Fatalf("\tContainer create failed: %v", err)
}
err = client.ContainerStart(context.Background(), r.ID,
types.ContainerStartOptions{})
if err != nil {
t.Fatalf("\tContainer start failed: id=%s, err %v", r.ID, err)
}
code, err := client.ContainerWait(context.Background(), r.ID)
if err != nil {
t.Fatalf("\tContainer wait failed: id=%s, err %v", r.ID, err)
}
if removeContainers == false {
t.Logf("\tSkipping container removal, id=%s (removeContainers == false)",
r.ID)
return code
}
err = client.ContainerRemove(context.Background(), r.ID,
types.ContainerRemoveOptions{
RemoveVolumes: true,
Force: true,
})
if err != nil {
t.Fatalf("\nContainer removal failed: %v", err)
}
return code
}