// Import the Docker Engine package library import ( "github.com/flynn/flynn/godeps/_workspace/src/github.com/docker/docker/engine" ) // Create a new Docker Engine client client, err := engine.NewClient() // Start a new container client.Job("create", engine.Args{ {"Image", "nginx"}, {"ExposedPorts", engine.PortSet{"80/tcp": {}}}, }) client.Stream("start", "containerID", engine.APIStopTimeout, false) // Stop the container client.Job("stop", engine.Args{{"ID", "containerID"}, {"Timeout", api.APIStopTimeout}}) client.Job("wait", engine.Args{{"ID", "containerID"}})
// Import the Docker Engine package library import ( "github.com/flynn/flynn/godeps/_workspace/src/github.com/docker/docker/engine" ) // Create a new Docker Engine client client, err := engine.NewClient() // List containers client.Job("list", engine.Args{{"Filters", filters.NewArgs(filters.KeyValuePair{Name: "status", Value: "running"})}}, func(job *engine.Job) error { fmt.Println(job.Status) containers, _ := job.ReadAll() var c map[string]engine.Container json.Unmarshal(containers, &c) for id := range c { fmt.Println(id) } return nil }) // Remove a container client.Job("remove", engine.Args{{"ID", "containerID"}}, func(job *engine.Job) error { fmt.Println(job.Status) return nil })In this example, the package library is used to create a new Docker Engine client, list running containers using a filter, and remove a specific container identified by "containerID".