()
| 23 | } |
| 24 | |
| 25 | func (docker *DockerService) Init() error { |
| 26 | client, err := client.NewClientWithOpts(client.FromEnv) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | |
| 31 | ctx := context.Background() |
| 32 | client.NegotiateAPIVersion(ctx) |
| 33 | |
| 34 | docker.client = client |
| 35 | docker.context = ctx |
| 36 | |
| 37 | _, err = docker.client.Ping(docker.context) |
| 38 | |
| 39 | if err != nil { |
| 40 | tlog.App.Debug().Err(err).Msg("Docker not connected") |
| 41 | docker.isConnected = false |
| 42 | docker.client = nil |
| 43 | docker.context = nil |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | docker.isConnected = true |
| 48 | tlog.App.Debug().Msg("Docker connected") |
| 49 | |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | func (docker *DockerService) getContainers() ([]container.Summary, error) { |
| 54 | containers, err := docker.client.ContainerList(docker.context, container.ListOptions{}) |
no outgoing calls