When pulling an image with ImagePull()
, there is extensive stdout in the terminal showing the progress of the Pull, i.e.;
{"status":"Downloading","progressDetail":{"current":6433248,"total":7964517},"progress":"[========================================\u003e ] 6.433MB/7.965MB","id":"ae5cee1a3f12"}
func PullImage(imageName string) bool {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
log.Error(err)
return false
}
//TODO: Need to disable Stdout!!
log.Info("\t\tPulling image " + imageName)
out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
if err != nil {
log.Error(err)
return false
}
defer out.Close()
io.Copy(os.Stdout, out)
log.Info("Pulled image " + imageName + " into host")
return true
}
I have searched the documentation and haven't found a way to disable StdOut or change verbosity.
I don't really understand the io.Copy(os.Stdout, out)
line, but disabling it causes no image to be pulled, as far as I can tell.
How can we hide the output from ImagePull()
?