-
Notifications
You must be signed in to change notification settings - Fork 12
/
docker.go
47 lines (38 loc) · 1022 Bytes
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Copyright (C) 2021-2023, Kubefirst
This program is licensed under MIT.
See the LICENSE file for more details.
*/
package docker
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/rs/zerolog/log"
)
func NewDockerClient() *client.Client {
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
log.Fatal().Msgf("error instantiating docker client: %s", err)
}
return cli
}
func (docker DockerClientWrapper) ListContainers() {
containers, err := docker.Client.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
for _, container := range containers {
fmt.Printf("%s %s\n", container.ID[:10], container.Image)
}
}
// CheckDockerReady
func (docker DockerClientWrapper) CheckDockerReady() (bool, error) {
_, err := docker.Client.Info(context.Background())
if err != nil {
log.Error().Msgf("error determining docker readiness: %s", err)
return false, err
}
return true, nil
}