I would like for this very simple Go package to run in a Docker container using Scratch (or minimal) image.
package main
import (
"fmt"
"os/exec"
)
func main() {
cmd := "host"
args := []string{"-t", "ns", "google.com"}
output, err := exec.Command(cmd, args...).Output()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(output))
}
My original Dockerfile is as follows:
FROM scratch
ADD gohost /
CMD ["/gohost"]
This results in exit code 0: exec: "host": executable file not found in $PATH
I figure this means I need to ADD the /usr/bin/host and set ENV on the added host.. but all the random combinations I've tried of this failed..
I've also tried to simply change cmd := "host" to point to the host binary I added (cmd := "/host"), but seems that isn't a possibility either.
Also, I'm not sure if it's relevant, but it's important the Go binary is built with env GOOS=linux GOARCH=arm64 go build.
hostexecutable into docker's path namespace.ADD /usr/bin/host /binand/usr/binbut that didn't work, and when I changed the Go code to point to the binary, e.g.cmd := "/host"then I made sure that the binary was located in that path, e.g.ADD /usr/bin/host /