當前位置: 首頁>>代碼示例>>Golang>>正文


Golang client.IsErrContainerNotFound函數代碼示例

本文整理匯總了Golang中github.com/docker/engine-api/client.IsErrContainerNotFound函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsErrContainerNotFound函數的具體用法?Golang IsErrContainerNotFound怎麽用?Golang IsErrContainerNotFound使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了IsErrContainerNotFound函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: inspectAll

func (cli *DockerCli) inspectAll(ctx context.Context, getSize bool) inspect.GetRefFunc {
	return func(ref string) (interface{}, []byte, error) {
		c, rawContainer, err := cli.client.ContainerInspectWithRaw(ctx, ref, getSize)
		if err != nil {
			// Search for image with that id if a container doesn't exist.
			if client.IsErrContainerNotFound(err) {
				i, rawImage, err := cli.client.ImageInspectWithRaw(ctx, ref, getSize)
				if err != nil {
					if client.IsErrImageNotFound(err) {
						// Search for task with that id if an image doesn't exists.
						t, rawTask, err := cli.client.TaskInspectWithRaw(ctx, ref)
						if err != nil {
							return nil, nil, fmt.Errorf("Error: No such image, container or task: %s", ref)
						}
						if getSize {
							fmt.Fprintln(cli.err, "WARNING: --size ignored for tasks")
						}
						return t, rawTask, nil
					}
					return nil, nil, err
				}
				return i, rawImage, err
			}
			return nil, nil, err
		}
		return c, rawContainer, err
	}
}
開發者ID:FlyingShit-XinHuang,項目名稱:docker,代碼行數:28,代碼來源:inspect.go

示例2: InspectContainer

func (d *kubeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error) {
	containerJSON, err := d.client.ContainerInspect(getDefaultContext(), id)
	if err != nil {
		if dockerapi.IsErrContainerNotFound(err) {
			return nil, containerNotFoundError{ID: id}
		}
		return nil, err
	}
	return &containerJSON, nil
}
開發者ID:mattjmcnaughton,項目名稱:kubernetes,代碼行數:10,代碼來源:kube_docker_client.go

示例3: GetContainer

// GetContainer looks up the hosts containers with the specified ID
// or name and returns it, or an error.
func GetContainer(ctx context.Context, clientInstance client.APIClient, id string) (*types.ContainerJSON, error) {
	container, err := clientInstance.ContainerInspect(ctx, id)
	if err != nil {
		if client.IsErrContainerNotFound(err) {
			return nil, nil
		}
		return nil, err
	}
	return &container, nil
}
開發者ID:haj,項目名稱:kompose,代碼行數:12,代碼來源:functions.go

示例4: InspectContainer

func (d *kubeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error) {
	ctx, cancel := d.getTimeoutContext()
	defer cancel()
	containerJSON, err := d.client.ContainerInspect(ctx, id)
	if ctxErr := contextError(ctx); ctxErr != nil {
		return nil, ctxErr
	}
	if err != nil {
		if dockerapi.IsErrContainerNotFound(err) {
			return nil, containerNotFoundError{ID: id}
		}
		return nil, err
	}
	return &containerJSON, nil
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:15,代碼來源:kube_docker_client.go

示例5: InspectContainer

func (d *kubeDockerClient) InspectContainer(id string) (*docker.Container, error) {
	containerJSON, err := d.client.ContainerInspect(getDefaultContext(), id)
	if err != nil {
		// TODO(random-liu): Use IsErrContainerNotFound instead of NoSuchContainer error
		if dockerapi.IsErrContainerNotFound(err) {
			err = &docker.NoSuchContainer{ID: id, Err: err}
		}
		return nil, err
	}
	container := &docker.Container{}
	if err := convertType(&containerJSON, container); err != nil {
		return nil, err
	}
	return container, nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:15,代碼來源:kube_docker_client.go

示例6: inspectAll

func (cli *DockerCli) inspectAll(getSize bool) inspectSearcher {
	return func(ref string) (interface{}, []byte, error) {
		c, rawContainer, err := cli.client.ContainerInspectWithRaw(ref, getSize)
		if err != nil {
			// Search for image with that id if a container doesn't exist.
			if client.IsErrContainerNotFound(err) {
				i, rawImage, err := cli.client.ImageInspectWithRaw(ref, getSize)
				if err != nil {
					if client.IsErrImageNotFound(err) {
						return nil, nil, fmt.Errorf("Error: No such image or container: %s", ref)
					}
					return nil, nil, err
				}
				return i, rawImage, err
			}
			return nil, nil, err
		}
		return c, rawContainer, err
	}
}
開發者ID:dfilion,項目名稱:docker,代碼行數:20,代碼來源:inspect.go

示例7: cleanUpDockerDandlingEndpoints

// cleanUpDockerDandlingEndpoints cleans all endpoints that are dandling by checking out
// if a particular endpoint has its container running.
func (d *Daemon) cleanUpDockerDandlingEndpoints() {
	eps, _ := d.EndpointsGet()
	if eps == nil {
		return
	}

	cleanUp := func(ep endpoint.Endpoint) {
		log.Infof("Endpoint %d not found in docker, cleaning up...", ep.ID)
		d.EndpointLeave(ep.ID)
		// FIXME: IPV4
		if ep.IPv6 != nil {
			if ep.IsCNI() {
				d.ReleaseIP(ipam.CNIIPAMType, ep.IPv6.IPAMReq())
			} else if ep.IsLibnetwork() {
				d.ReleaseIP(ipam.LibnetworkIPAMType, ep.IPv6.IPAMReq())
			}
		}

	}

	for _, ep := range eps {
		log.Debugf("Checking if endpoint is running in docker %d", ep.ID)
		if ep.DockerNetworkID != "" {
			nls, err := d.dockerClient.NetworkInspect(ctx.Background(), ep.DockerNetworkID)
			if dockerAPI.IsErrNetworkNotFound(err) {
				cleanUp(ep)
				continue
			}
			if err != nil {
				continue
			}
			found := false
			for _, v := range nls.Containers {
				if v.EndpointID == ep.DockerEndpointID {
					found = true
					break
				}
			}
			if !found {
				cleanUp(ep)
				continue
			}
		} else if ep.DockerID != "" {
			cont, err := d.dockerClient.ContainerInspect(ctx.Background(), ep.DockerID)
			if dockerAPI.IsErrContainerNotFound(err) {
				cleanUp(ep)
				continue
			}
			if err != nil {
				continue
			}
			if !cont.State.Running {
				cleanUp(ep)
				continue
			}
		} else {
			cleanUp(ep)
			continue
		}
	}
}
開發者ID:cilium-team,項目名稱:cilium,代碼行數:63,代碼來源:state.go


注:本文中的github.com/docker/engine-api/client.IsErrContainerNotFound函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。