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


Golang Client.ImageInspectWithRaw方法代碼示例

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


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

示例1: buildTorImage

func buildTorImage(cli *client.Client, ctx io.Reader) (string, error) {
	// XXX: There's currently no way to get the image ID of a build without
	//      manually parsing the output, or tagging the image. Since I'm not in
	//      the mood for the former, we can tag the build with a random name.
	//      Unfortunately, untagging of images isn't supported, so we'll have to
	//      use a name that allows us to not pollute the host.

	options := types.ImageBuildOptions{
		// XXX: If we SuppressOutput we can get just the image ID, but we lose
		//      being able to tell users what the status of the build is.
		//SuppressOutput: true,
		Tags:        []string{MkonionTag},
		Remove:      true,
		ForceRemove: true,
		Dockerfile:  "Dockerfile",
		Context:     ctx,
	}

	build, err := cli.ImageBuild(options)
	if err != nil {
		return "", err
	}

	// XXX: For some weird reason, at this point the build has not finished. We
	//      need to wait for build.Body to be closed. We might as well tell the
	//      user what the status of the build is.
	log.Infof("building %s", MkonionTag)
	dec := json.NewDecoder(build.Body)
	for {
		// Modified from pkg/jsonmessage in Docker.
		type JSONMessage struct {
			Stream string `json:"stream,omitempty"`
			Status string `json:"status,omitempty"`
		}

		// Decode the JSONMessages.
		var jm JSONMessage
		if err := dec.Decode(&jm); err != nil {
			if err == io.EOF {
				break
			}
			return "", err
		}

		jm.Stream = strings.TrimSpace(jm.Stream)
		jm.Status = strings.TrimSpace(jm.Status)

		// Log the status.
		if jm.Stream != "" {
			log.Info(jm.Stream)
		}
		if jm.Status != "" {
			log.Info(jm.Status)
		}
	}

	inspect, _, err := cli.ImageInspectWithRaw(MkonionTag, false)
	if err != nil {
		// XXX: Should probably clean up the built image here?
		return "", err
	}

	log.Infof("successfully built %s image", MkonionTag)
	return inspect.ID, nil
}
開發者ID:cyphar,項目名稱:mkonion,代碼行數:65,代碼來源:fakebuild.go


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