mirror of
https://github.com/docker/cli.git
synced 2026-09-25 07:50:37 -05:00
From Go 1.8 HTTP client redirect behaviour is changed: When status code is 301, 307 or 308, the client automatically converts it to a new HTTP request. This behaviour change manifests in the client in that before the 301 was not followed and the client did not generate an error, but now results in an error message: "Error response from daemon: page not found." To fix that a new redirect policy is forced by setting HTTP Client's CheckRedirect. That policy is to return an error for any 301, 307 or 308 in the response's status code to a non-GET request. The error message specifies that the daemon could not process the request and it is probably due to bad arguments that were provided by the user. Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com> Upstream-commit: eb36d6021618f788012c166a533f1b321cda9695 Component: engine
Go client for the Docker Engine API
The docker command uses this package to communicate with the daemon. It can also be used by your own Go applications to do anything the command-line interface does – running containers, pulling images, managing swarms, etc.
For example, to list running containers (the equivalent of docker ps):
package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
func main() {
cli, err := client.NewEnvClient()
if err != nil {
panic(err)
}
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
for _, container := range containers {
fmt.Printf("%s %s\n", container.ID[:10], container.Image)
}
}