dqst96444
2015-05-22 21:49
浏览 430

构建后如何从API获取Docker镜像ID?

According to the Docker v1.18 API documentation, the /build method accepts a TAR stream (with a Dockerfile) and attempts to build the image.

However, unless I'm missing something, there seems to be no way to obtain the image ID after the build process completes.

For example, I'm using the go-dockerclient library to connect to the Docker API and build the image using the following snippet:

//...

opts := docker.BuildImageOptions{
    Name:         "test-image",
    InputStream:  input,
    OutputStream: output,
}

if err := client.BuildImage(opts); err != nil {
    fmt.Println(err)
}

//...

The BuildImage() method executes and I can confirm (through Docker's CLI client) that the image is indeed created. However, the only value returned from BuildImage() is an error. There doesn't seem to be a way to obtain the ID of the image.

Am I missing something?

图片转代码服务由CSDN问答提供 功能建议

根据 Docker v1.18 API文档 / build 方法接受TAR流(带有Dockerfile) 并尝试构建映像。

但是,除非丢失了某些内容,否则似乎无法在构建过程完成后获取映像ID。

例如,我正在使用 go-dockerclient库 连接到Docker API并使用以下代码段构建映像:

  // ... 
 
opts:= docker.BuildImageOptions {
名称:“ test  -image“,
 InputStream:输入,
 OutputStream:输出,
} 
 
if err:= client.BuildImage(opts);  err!= nil {
 fmt.Println(err)
} 
 
 // ... 
   
 
 

BuildImage()< / code>方法执行后,我可以(通过Docker的CLI客户端)确认确实创建了映像。 但是,从 BuildImage()返回的唯一值是一个错误。 似乎没有一种获取图像ID的方法。

我错过了什么吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题