Skip to content

Instantly share code, notes, and snippets.

@kuozo
Created October 9, 2018 01:54
Show Gist options
  • Save kuozo/150e51260d7bfd7886622a8478b425dc to your computer and use it in GitHub Desktop.
Save kuozo/150e51260d7bfd7886622a8478b425dc to your computer and use it in GitHub Desktop.
Docker Client
package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
)
func main() {
cli, err := client.NewClient(client.DefaultDockerHost, "", nil, nil)
if err != nil {
fmt.Println("client error")
fmt.Println(err)
}
args := filters.NewArgs()
args.Add("status", "running")
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: true, Filters: args})
if err != nil {
fmt.Println("container error")
fmt.Println(err)
}
for _, container := range containers {
fmt.Println("Container ID: ", container.ID)
fmt.Println("Container Image ID:", container.ImageID)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment