How to Spin up docker container & run some command via golang script?

Viewed 194

I am planning to automate spinning up container and run some commands on it. But I get the below error

docker run -it alpine sh ls

Error I get is

docker error : the input device is not a TTY.

So I removed interactive part and ran

docker run -t alpine sh ls

I don't get the shell but docker is spinning

I run above docker commands in golangs os.exec package.

package main
import (
    "fmt"
    "os"
    "os/exec"
    "sync"
)
func main() {
    var wg sync.WaitGroup
wg.Add(1)
    go func() {
        defer wg.Done()
        cmd := exec.Command("docker", "run","-it","alpine","sh","ls")
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
        cmd.Run()
        // log.Println(cmd.Run())
    }()
}()
    wg.Wait()
}

My intention is to run multiple shell scripts after spinning up the docker.

Any help would be appreciated. Thanks

1 Answers
Related