亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Docker SDK 從文件加載圖像

使用 Docker SDK 從文件加載圖像

Go
弒天下 2022-05-18 13:44:18
我使用 ImageLoad 函數來加載圖像:    file, err := os.OpenFile(fileName, os.O_RDONLY, 0666)    if err != nil {        log.Debugf("Error loading image %s, %s", fileName, err)    } else {        defer file.Close()        resp, err := client.api.ImageLoad(ctx, file, false)        if err != nil {            log.Debugf("Error loading image %s, %s", fileName, err)        }        if resp.Body == nil {            err = errors.New("Error loading image")        } else {            defer resp.Body.Close()        }    }但是如果我加載一個不是圖像的文件,我沒有錯誤。如果我使用控制臺,它會按預期工作:$ docker load -i s.taropen /var/lib/docker/tmp/docker-import-075289246/repositories: no such file or directory那么,為什么我在 SDK 的情況下沒有錯誤?
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

我為我添加了工作示例:


package main


import (

    "bytes"

    "fmt"

    "io/ioutil"

    "log"


    "github.com/docker/docker/client"

    "golang.org/x/net/context"

)


func main() {

    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())

    if err != nil {

        panic(err)

    }

    input := bytes.NewReader([]byte("dummy content\n"))

    imageLoadResponse, err := cli.ImageLoad(context.Background(), input, true)

    if err != nil {

        log.Fatal(err)

    }

    body, err := ioutil.ReadAll(imageLoadResponse.Body)

    fmt.Println(string(body))

}

//Output:

// {"errorDetail":{"message":"Error processing tar file(exit status 1): unexpected EOF"},"error":"Error processing tar file(exit status 1): unexpected EOF"}


您還可以查看docker load 命令的方式


查看完整回答
反對 回復 2022-05-18
  • 1 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號