container.go 863 B

123456789101112131415161718192021222324252627282930313233343536
  1. package daemon
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/docker/docker/api/types/container"
  6. "gotest.tools/v3/assert"
  7. )
  8. // ActiveContainers returns the list of ids of the currently running containers
  9. func (d *Daemon) ActiveContainers(ctx context.Context, t testing.TB) []string {
  10. t.Helper()
  11. cli := d.NewClientT(t)
  12. defer cli.Close()
  13. containers, err := cli.ContainerList(context.Background(), container.ListOptions{})
  14. assert.NilError(t, err)
  15. ids := make([]string, len(containers))
  16. for i, c := range containers {
  17. ids[i] = c.ID
  18. }
  19. return ids
  20. }
  21. // FindContainerIP returns the ip of the specified container
  22. func (d *Daemon) FindContainerIP(t testing.TB, id string) string {
  23. t.Helper()
  24. cli := d.NewClientT(t)
  25. defer cli.Close()
  26. i, err := cli.ContainerInspect(context.Background(), id)
  27. assert.NilError(t, err)
  28. return i.NetworkSettings.IPAddress
  29. }