api.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Ports []Port
  19. }
  20. // Port represents a published port of a container
  21. type Port struct {
  22. // HostPort is the port number on the host
  23. HostPort uint32
  24. // ContainerPort is the port number inside the container
  25. ContainerPort uint32
  26. /// Protocol is the protocol of the port mapping
  27. Protocol string
  28. // HostIP is the host ip to use
  29. HostIP string
  30. }
  31. // ContainerConfig contains the configuration data about a container
  32. type ContainerConfig struct {
  33. // ID uniquely identifies the container
  34. ID string
  35. // Image specifies the iamge reference used for a container
  36. Image string
  37. // Ports provide a list of published ports
  38. Ports []Port
  39. // Labels set labels to the container
  40. Labels map[string]string
  41. }
  42. // LogsRequest contains configuration about a log request
  43. type LogsRequest struct {
  44. Follow bool
  45. Tail string
  46. Writer io.Writer
  47. }
  48. // Service interacts with the underlying container backend
  49. type Service interface {
  50. // List returns all the containers
  51. List(ctx context.Context, all bool) ([]Container, error)
  52. // Stop stops the running container
  53. Stop(ctx context.Context, containerID string, timeout *uint32) error
  54. // Run creates and starts a container
  55. Run(ctx context.Context, config ContainerConfig) error
  56. // Exec executes a command inside a running container
  57. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  58. // Logs returns all the logs of a container
  59. Logs(ctx context.Context, containerName string, request LogsRequest) error
  60. // Delete removes containers
  61. Delete(ctx context.Context, id string, force bool) error
  62. }