api.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package containers
  2. import (
  3. "context"
  4. "io"
  5. )
  6. // Container represents a created container
  7. type Container struct {
  8. ID string
  9. Status string
  10. Image string
  11. Command string
  12. CPUTime uint64
  13. MemoryUsage uint64
  14. MemoryLimit uint64
  15. PidsCurrent uint64
  16. PidsLimit uint64
  17. Labels []string
  18. }
  19. // Port represents a published port of a container
  20. type Port struct {
  21. // Source is the source port
  22. Source uint32
  23. // Destination is the destination port
  24. Destination uint32
  25. }
  26. // ContainerConfig contains the configuration data about a container
  27. type ContainerConfig struct {
  28. // ID uniquely identifies the container
  29. ID string
  30. // Image specifies the iamge reference used for a container
  31. Image string
  32. // Ports provide a list of published ports
  33. Ports []Port
  34. }
  35. // LogsRequest contains configuration about a log request
  36. type LogsRequest struct {
  37. Follow bool
  38. Tail string
  39. Writer io.Writer
  40. }
  41. // Service interacts with the underlying container backend
  42. type Service interface {
  43. // List returns all the containers
  44. List(ctx context.Context) ([]Container, error)
  45. // Run creates and starts a container
  46. Run(ctx context.Context, config ContainerConfig) error
  47. // Exec executes a command inside a running container
  48. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  49. // Logs returns all the logs of a container
  50. Logs(ctx context.Context, containerName string, request LogsRequest) error
  51. }