1package daemon
2
3import (
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
12func (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
30func (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}
41