Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Howto: Run an exec command on a running container #173

Open
beatscode opened this issue Oct 8, 2015 · 2 comments
Open

Howto: Run an exec command on a running container #173

beatscode opened this issue Oct 8, 2015 · 2 comments

Comments

@beatscode
Copy link

Hello, I'm trying to run a command on a running container. I'm not sure what I'm doing wrong. Could you assist. Running the test below returns the following:

vagrant@vagrant-ubuntu-trusty-64:~/go/src/com.stuff/ambassador$ go test -test.run TestExec -v=== RUN TestExec
dac07107d20a5834826f16547945d5afe6b714fcefe0820fd64e5ea8b27b1aaf
--- PASS: TestExec (0.01s)
PASS
func TestExec(t *testing.T) {
    //var sContainer dockerclient.Container
    var config dockerclient.ExecConfig
    containers, err := docker.ListContainers(true, false, "")
    if err != nil {
        t.Fatalf("cannot get containers: %s", err)
    }
    for _, c := range containers {
        for _, name := range c.Names {
            if name == "/testapi" {
                config.Container = c.Id
            }
        }
    }
    if config.Container == "" {
        t.Error("Container Not found")
    }
    config.Cmd = []string{"bash", "-c", "date"}
    config.AttachStdout = true
    config.AttachStderr = true
    config.AttachStdin = false
    config.Tty = false
    config.Detach = false
    ID, err := docker.ExecCreate(&config)
    fmt.Println(ID)
    if err != nil {
        t.Error(err)
    }

    config.Cmd = []string{}
    config.AttachStdout = true
    config.AttachStderr = true
    config.AttachStdin = true
    config.Tty = true
    config.Detach = true
    //fmt.Print(config)
    err = docker.ExecStart(ID, &config)
    if err != nil {
        t.Error(err)
    }

    //fmt.Print(containers)
}

How do I run a command and trap the response?

@hekaldama
Copy link

@beatscode did you figure this out? I am of need of this as well.

@hekaldama
Copy link

Anyone know how to do this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants