github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/internal/test/daemon/container.go (about) 1 package daemon 2 3 import ( 4 "context" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/internal/test" 8 "gotest.tools/assert" 9 ) 10 11 // ActiveContainers returns the list of ids of the currently running containers 12 func (d *Daemon) ActiveContainers(t assert.TestingT) []string { 13 if ht, ok := t.(test.HelperT); ok { 14 ht.Helper() 15 } 16 cli := d.NewClientT(t) 17 defer cli.Close() 18 19 containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{}) 20 assert.NilError(t, err) 21 22 ids := make([]string, len(containers)) 23 for i, c := range containers { 24 ids[i] = c.ID 25 } 26 return ids 27 } 28 29 // FindContainerIP returns the ip of the specified container 30 func (d *Daemon) FindContainerIP(t assert.TestingT, id string) string { 31 if ht, ok := t.(test.HelperT); ok { 32 ht.Helper() 33 } 34 cli := d.NewClientT(t) 35 defer cli.Close() 36 37 i, err := cli.ContainerInspect(context.Background(), id) 38 assert.NilError(t, err) 39 return i.NetworkSettings.IPAddress 40 }