本文整理汇总了Golang中github.com/samalba/dockerclient.DockerClient类的典型用法代码示例。如果您正苦于以下问题:Golang DockerClient类的具体用法?Golang DockerClient怎么用?Golang DockerClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DockerClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteImage
func deleteImage(docker *dockerclient.DockerClient, imageIDs []string) []error {
var errors []error
if !noConfirm {
var answer string
fmt.Printf("This will delete %v images\n", len(imageIDs))
fmt.Printf("Do you want to continue? (yes/no)\n")
fmt.Scanln(&answer)
if answer != "yes" {
fmt.Printf("%v", answer)
return nil
}
}
for _, imageID := range imageIDs {
imageDelete, deleteErr := docker.RemoveImage(imageID)
if deleteErr != nil {
errors = append(errors, deleteErr)
}
for _, id := range imageDelete {
if id.Deleted != "" {
log.Printf("DELETED: %v", id.Deleted)
}
if id.Untagged != "" {
log.Printf("UNTAGGED: %#v", id.Untagged)
}
}
}
if len(errors) > 0 {
return errors
}
return nil
}
示例2: GetContainers
func (n *Node) GetContainers(do *dockerclient.DockerClient) ([]dockerclient.Container, error) {
containers, err := do.ListContainers(false, false, "")
if err != nil {
log.Fatal(err)
}
return containers, err
}
示例3: GetImages
func (n *Node) GetImages(do *dockerclient.DockerClient) ([]*dockerclient.Image, error) {
images, err := do.ListImages(false)
if err != nil {
log.Fatal(err)
}
return images, err
}
示例4: ListImagesDetailed
func ListImagesDetailed(dockerClient *dockerclient.DockerClient, all bool) ([]*DetailedImageInfo, error) {
images, err := dockerClient.ListImages(all)
if err != nil {
return nil, err
}
var result = make([]*DetailedImageInfo, len(images))
for i, image := range images {
imagesDetails, _ := InspectImage(dockerClient, image.Id)
detailedImageInfo := DetailedImageInfo{
Created: image.Created,
Id: image.Id,
ParentId: image.ParentId,
RepoTags: image.RepoTags,
Size: image.Size,
VirtualSize: image.VirtualSize,
Architecture: imagesDetails.Architecture,
Author: imagesDetails.Author,
Comment: imagesDetails.Comment,
Container: imagesDetails.Container,
DockerVersion: imagesDetails.Container,
Os: imagesDetails.Os}
result[i] = &detailedImageInfo
}
return result, nil
}
示例5: stopCotainers
func stopCotainers(docker *dockerclient.DockerClient, imageIDs []string) []error {
var errors []error
if !noConfirm {
var answer string
fmt.Printf("This will stop %v images\n", len(imageIDs))
fmt.Printf("Do you want to continue? (yes/no)\n")
fmt.Scanln(&answer)
if answer != "yes" {
fmt.Printf("%v", answer)
return nil
}
}
for _, imageID := range imageIDs {
stopErr := docker.StopContainer(imageID, 10)
if stopErr != nil {
errors = append(errors, stopErr)
} else {
log.Printf("STOPPED: %v", imageID)
}
}
if len(errors) > 0 {
return errors
}
return nil
}
示例6: InspectContainer
func (n *Node) InspectContainer(do *dockerclient.DockerClient, id string) (*dockerclient.ContainerInfo, error) {
containerInfo := &dockerclient.ContainerInfo{}
var err error
containerInfo, err = do.InspectContainer(id)
if err != nil {
log.Fatal(err)
}
return containerInfo, err
}
示例7: stopAndDeleteDevice
func stopAndDeleteDevice(deviceSn string, docker *dc.DockerClient) error {
container := "device" + deviceSn
err := docker.KillContainer(container)
if err != nil {
return err
}
err = docker.RemoveContainer(container)
return nil
}
示例8: removeImages
func removeImages(client *dockerclient.DockerClient, images []*dockerclient.Image) error {
for _, image := range images {
log.Print("rmi ", image.Id)
if !*dry {
if _, err := client.RemoveImage(image.Id); err != nil {
debug("Couldn't remove image: %s", err)
}
}
}
return nil
}
示例9: GetInjectorsForPolicy
func GetInjectorsForPolicy(client *docker.DockerClient, name string) ([]injector, error) {
is := []injector{}
cs, err := client.ListContainers(true, false, fmt.Sprintf(`{"label":["%s=%s"]}`, AGENT_LABEL, name))
if err != nil {
return is, err
}
for _, c := range cs {
is = append(is, InjectorFromContainer(c))
}
return is, nil
}
示例10: removeContainers
func removeContainers(client *dockerclient.DockerClient, containers []*dockerclient.ContainerInfo) error {
for _, container := range containers {
log.Printf("rm %s (%s)", container.Id, container.Name)
if !*dry {
if err := client.RemoveContainer(container.Id, false, false); err != nil {
debug("Couldn't remove container: %s", err)
}
}
}
return nil
}
示例11: ListContainersDetailed
func ListContainersDetailed(dockerClient *dockerclient.DockerClient) ([]*dockerclient.ContainerInfo, error) {
containers, err := dockerClient.ListContainers(true, false, "")
if err != nil {
return nil, err
}
var result = make([]*dockerclient.ContainerInfo, len(containers))
for i, container := range containers {
containerInfo, err := dockerClient.InspectContainer(container.Id)
if err != nil {
return nil, err
}
result[i] = containerInfo
}
return result, nil
}
示例12: list_containers
func list_containers(docker *dockerclient.DockerClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Get only running containers
containers, err := docker.ListContainers(false, false, "")
if err != nil {
log.Fatal(err)
}
dat, err := json.MarshalIndent(&containers, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(w, string(dat))
}
}
示例13: startContainer
func startContainer(docker *dockerclient.DockerClient, containerId string, additionalCapabilities []string, ctx *ContainerContext) error {
//Build the port bindings needed when running the container
dockerHostConfig := new(dockerclient.HostConfig)
dockerHostConfig.PortBindings = make(map[string][]dockerclient.PortBinding)
for k, v := range ctx.PortContext {
pb := dockerclient.PortBinding{HostPort: v}
portBindings := []dockerclient.PortBinding{pb}
dockerHostConfig.PortBindings[k] = portBindings
}
dockerHostConfig.Links = ctx.Links
dockerHostConfig.CapAdd = additionalCapabilities
//Start the container
return docker.StartContainer(containerId, dockerHostConfig)
}
示例14: requiredImageAvailable
func requiredImageAvailable(docker *dockerclient.DockerClient, name string) bool {
images, err := docker.ListImages(true)
if err != nil {
log.Fatal(err)
}
for _, i := range images {
for _, t := range i.RepoTags {
if strings.Index(t, name) == 0 {
return true
}
}
}
return false
}
示例15: InspectImage
func InspectImage(dockerClient *dockerclient.DockerClient, id string) (*dockerclient.ImageInfo, error) {
cachedImageInfo, _ := imageCache.Get(id)
if cachedImageInfo == nil {
imageInfo, err := dockerClient.InspectImage(id)
if err != nil {
return nil, err
}
imageCache.Add(id, imageInfo)
return imageInfo, nil
} else {
if cachedImageInfoCasted, ok := cachedImageInfo.(*dockerclient.ImageInfo); ok {
return cachedImageInfoCasted, nil
} else {
return nil, fmt.Errorf("Cache casting error")
}
}
}