-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.go
51 lines (39 loc) · 1.14 KB
/
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
48
49
50
51
package ido
import "strings"
type docker struct{}
func newDocker() *docker {
return &docker{}
}
func (d docker) create(image string) (container string, err error) {
sh := newShell("docker", "create", image)
result, err := sh.result()
if err != nil {
return "", err
}
// --- result example ---
// Unable to find image 'foo:latest' locally
// latest: Pulling from library/foo
// abcdefghijkl: Pulling fs layer
// abcdefghijkl: Download complete
// abcdefghijkl: Pull complete
// Digest: sha256:abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
// Status: Downloaded newer image for foo:latest
// abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01
lines := strings.Split(result, "\n")
container = lines[len(lines)-1]
return container, nil
}
func (d docker) export(outputDir string, container string) (err error) {
sh := newShell("docker", "export", "-o", outputDir, container)
if _, err = sh.result(); err != nil {
return err
}
return nil
}
func (d docker) rm(container string) (err error) {
sh := newShell("docker", "rm", container)
if _, err = sh.result(); err != nil {
return err
}
return nil
}