Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larzconwell/2b35465add94f6005779 to your computer and use it in GitHub Desktop.
Save larzconwell/2b35465add94f6005779 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/fsouza/go-dockerclient"
"os"
"fmt"
)
func main() {
client, err := docker.NewClient("unix:///var/run/docker.sock")
if err != nil {
panic(err)
}
opts := docker.CreateContainerOptions{
Config: &docker.Config{
AttachStdout: true,
AttachStderr: true,
Tty: true,
Cmd: []string{"watch", "date"},
Image: "ubuntu",
},
}
container, err := client.CreateContainer(opts)
if err != nil {
panic(err)
}
err = client.StartContainer(container.ID, nil)
if err != nil {
panic(err)
}
err = client.AttachToContainer(docker.AttachToContainerOptions{
Container: container.ID,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
Stdout: true,
Stderr: true,
})
if err != nil {
panic(err)
}
n, err := client.WaitContainer(container.ID)
if err != nil {
panic(err)
}
fmt.Println(n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment