Created
October 9, 2018 01:54
-
-
Save kuozo/150e51260d7bfd7886622a8478b425dc to your computer and use it in GitHub Desktop.
Docker Client
This file contains 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 ( | |
"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