-
Notifications
You must be signed in to change notification settings - Fork 0
/
internals.go
53 lines (41 loc) · 941 Bytes
/
internals.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
50
51
52
53
package main
import (
"os/exec"
"log"
"strings"
)
type containerDetails struct {
ID string `json:"id"`
Name string `json:"name"`
IP string `json:"ip"`
Tag string `json:"tag"`
}
func Run(name, tag string) containerDetails {
arg := []string{name, tag}
args := strings.Join(arg, ":")
log.Print(args)
id := runAndReturnID(args)
ip := getIP(id)
detailedContainer := containerDetails {
ID: id,
Name: name,
IP: ip,
Tag: tag,
}
return detailedContainer
}
func runAndReturnID(args string) string {
out, err := exec.Command("docker", "run", "-d", args).Output()
if err != nil {
log.Fatal(err)
}
return string(out)[:12]
}
func getIP(id string) string {
format := "--format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'"
ip, err := exec.Command("docker", "inspect", format, id).Output()
if err != nil {
log.Fatal(err)
}
return string(ip)
}