import ( "github.com/fsouza/go-dockerclient" "fmt" ) func main() { client, err := docker.NewClient("unix:///var/run/docker.sock") if err != nil { panic(err) } // Get list of containers containers, err := client.ListContainers(docker.ListContainersOptions{}) if err != nil { panic(err) } for _, container := range containers { fmt.Println(container.Names) } }
import ( "github.com/fsouza/go-dockerclient" "fmt" ) func main() { client, err := docker.NewClientFromEnv() if err != nil { panic(err) } // Get list of running containers containers, err := client.ListContainers(docker.ListContainersOptions{All: false}) if err != nil { panic(err) } for _, container := range containers { fmt.Println(container.ID) } }In this example, we use the `NewClientFromEnv` method to create a Docker client that connects to the Docker daemon using environment variables. Then we call the `ListContainers` method with the `All` option set to `false` to get a list of only the running containers and print their IDs to the console. Overall, the `github.com.fsouza.go-dockerclient` package library provides a convenient way to interact with Docker from Go and the `ListContainers` method is just one of many useful methods for managing containers.