Skip to content

Instantly share code, notes, and snippets.

@mrunalp
Created September 30, 2015 00:15
Show Gist options
  • Save mrunalp/2d5b57b8c4c3155edcf6 to your computer and use it in GitHub Desktop.
Save mrunalp/2d5b57b8c4c3155edcf6 to your computer and use it in GitHub Desktop.
Test stdin through API
package main
import (
"log"
"github.com/fsouza/go-dockerclient"
)
func main() {
endpoint := "unix:///var/run/docker.sock"
client, err := docker.NewClient(endpoint)
if err != nil {
log.Fatal(err)
}
config := &docker.Config{
Image: "library/alpine",
StdinOnce: true,
OpenStdin: true,
Tty: true,
Cmd: []string{"cat"},
}
copt := docker.CreateContainerOptions{
Name: "mytestcontainer",
Config: config,
}
cont, err := client.CreateContainer(copt)
if err != nil {
log.Fatalf("Failed to create container %q", err)
}
if err := client.StartContainer(cont.ID, nil); err != nil {
log.Fatalf("Failed to start container %q", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment