本文整理汇总了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
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}
}
}