import ( "context" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" ) func main() { ctx := context.Background() cli, err := client.NewEnvClient() resp, err := cli.ContainerCreate(ctx, &container.Config{ Image: "nginx:latest", Tty: true, AttachStdout: true, AttachStderr: true, Hostname: "my-nginx", Mounts: []mount.Mount{ { Type: mount.TypeBind, Source: "/path/to/host/files", Target: "/path/to/container/files", }, }, }, nil, nil, "my-nginx") err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) }
import ( "context" "github.com/docker/docker/api/types" "github.com/docker/docker/client" ) func main() { ctx := context.Background() cli, err := client.NewEnvClient() containers, err := cli.ContainerList(ctx, types.ContainerListOptions{ All: true, }) for _, container := range containers { fmt.Println(container.Names[0]) } }This code lists all running containers on the Docker daemon, including those that are not currently running. Overall, the go github.com.docker.docker.daemon package is a powerful toolset for managing Docker environments using Go.