I am using the following Golang code to pull containerd image.
package main
import (
"context"
"log"
"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
)
func main() {
// create connection to containerd
client, err := containerd.New("/run/containerd/containerd.sock")
if err != nil {
log.Fatal(err)
}
defer client.Close()
// use k8s.io namespace
ctx := namespaces.WithNamespace(context.Background(), "k8s.io")
// pull image
image, err := client.Pull(ctx, "docker.io/library/openjdk:17", containerd.WithPullUnpack)
if err != nil {
log.Fatal(err)
}
log.Printf(" Pulled image: %s", image.Name())
}
The code worked well and silently pulled the image for me.
The question is, can I show the progress (e.g print BytesPulled/BytesTotal on console) during the pull? Any idea will be appreciated.
I am using golang code to pull containerd image. I want to show pull progress during the pull.
I am using the following code.
package main
import (
"context"
"log"
"github.com/containerd/containerd"
"github.com/containerd/containerd/namespaces"
)
func main() {
// create connection to containerd
client, err := containerd.New("/run/containerd/containerd.sock")
if err != nil {
log.Fatal(err)
}
defer client.Close()
// use k8s.io namespace
ctx := namespaces.WithNamespace(context.Background(), "k8s.io")
// pull image
image, err := client.Pull(ctx, "docker.io/library/openjdk:17", containerd.WithPullUnpack)
if err != nil {
log.Fatal(err)
}
log.Printf(" Pulled image: %s", image.Name())
}
The code worked well and silently pulled the image for me.
The question is, can I show the progress (e.g print BytesPulled/BytesTotal on console) during the pull? Any idea will be appreciated.