When using the ImagePull method in the Go Docker SDK to pull the CentOS image, if the image name and version appear as "none", it usually means that the image's name or tag was not specified correctly.

To pull a specific version of the CentOS image, you need to provide the full image name and tag. The tag represents the version of the image you want to pull.

Here's an example of how to correctly pull a specific CentOS image version using the Docker SDK in Go:

package main

import (
	"context"
	"fmt"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
)

func main() {
	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		panic(err)
	}

	imageName := "centos"
	imageTag := "7" // Replace with the desired CentOS version

	out, err := cli.ImagePull(context.Background(), imageName+":"+imageTag, types.ImagePullOptions{})
	if err != nil {
		panic(err)
	}

	defer out.Close()
	
	// Print the output
	buf := make([]byte, 8*1024)
	for {
		n, err := out.Read(buf)
		if err != nil {
			break
		}
		fmt.Print(string(buf[:n]))
	}
}

Make sure to replace imageTag with the desired CentOS version (e.g., "7", "8", etc.).

golang docker sdk中用ImagePull方法拉取的centos镜像的镜像名和版本号都是none

原文地址: https://www.cveoy.top/t/topic/ia2G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录