import ( "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" "golang.org/x/net/context" ) func createVolume(volName string) error { // Create a Docker client using the default configuration cli, err := client.NewEnvClient() if err != nil { return err } // Specify the options for the new volume options := volume.VolumeCreateBody{ Name: volName, } // Create the new volume using the specified options _, err = cli.VolumeCreate(context.Background(), options) if err != nil { return err } return nil }
import ( "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/client" "golang.org/x/net/context" ) func listVolumes() error { // Create a Docker client using the default configuration cli, err := client.NewEnvClient() if err != nil { return err } // Get a list of all volumes volumes, err := cli.VolumeList(context.Background(), types.VolumeListOptions{}) if err != nil { return err } // Print the name of each volume to the console for _, vol := range volumes.Volumes { fmt.Println(vol.Name) } return nil }