April 2018
Intermediate to advanced
250 pages
5h 42m
English
Let's write a simple script that interacts with Docker:
#!/usr/bin/env gorunpackage mainimport ( "fmt" "context" "github.com/docker/docker/client")func main() { ctx := context.Background() cli, err := client.NewClient(client.DefaultDockerHost, "1.30", nil, nil) if err != nil { panic(err) } info, err := cli.Info(ctx) if err != nil { panic(err) } fmt.Println(info.ServerVersion)}
First, the script must have the first line with shebang and gorun. Second, import a line with Docker's client library, github.com/docker/docker/client. Although, Docker has been moved to github.com/moby/moby, but we still need to import all related library using the docker/docker repository name. Just go get github.com/docker/docker/client and everything ...
Read now
Unlock full access