Created
September 30, 2015 00:15
-
-
Save mrunalp/2d5b57b8c4c3155edcf6 to your computer and use it in GitHub Desktop.
Test stdin through API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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