The documentation clearly says:
This operation is used by the Amazon ECR proxy, and it is not intended
for general use by customers for pulling and pushing images. In most
cases, you should use the docker CLI to pull, tag, and push images.
Instead doing that way I will recommend you to use exec
Go package and implement the exec commands directly in your build machine.
You can do something like this:
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
name := "docker"
args := []string{"push", "registry/name:tag"}
cmd := exec.Command(name, args...)
if err := cmd.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println("done")
}
I took this example from the this blog https://nathanleclaire.com/blog/2014/12/29/shelled-out-commands-in-golang/
I hope you can have this info useful