-
Notifications
You must be signed in to change notification settings - Fork 0
/
running.go
49 lines (41 loc) · 1.08 KB
/
running.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
48
49
package admindocker
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
func (s *AdminDockerStore) UpdateRunning() bool {
// ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
panic(err)
}
/*
ID:30c
Image:nsip/hitsproxy
Command:/go/bin/hitsproxy
Created:1589669100
Ports:[{IP:0.0.0.0 PrivatePort:8089 PublicPort:8089 Type:tcp}]
SizeRw:0 SizeRootFs:0 Labels:map[] State:running
Status:Up 14 minutes HostConfig:{NetworkMode:default}
NetworkSettings:0xc0000105b0 Mounts:[]}
*/
s.Containers = nil
for _, container := range containers {
ports := make([]uint16, 0)
// XXX map?
for _, port := range container.Ports {
ports = append(ports, port.PublicPort)
}
s.Containers = append(s.Containers, AdminDockerContainer{
ID: string(container.ID),
Image: container.Image,
Ports: ports,
})
}
return true
}