api.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  40. // LogsRequest contains configuration about a log request
  41. type LogsRequest struct {
  42. Follow bool
  43. Tail string
  44. Writer io.Writer
  45. }
  46. // Service interacts with the underlying container backend
  47. type Service interface {
  48. // List returns all the containers
  49. List(ctx context.Context) ([]Container, error)
  50. // Run creates and starts a container
  51. Run(ctx context.Context, config ContainerConfig) error
  52. // Exec executes a command inside a running container
  53. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  54. // Logs returns all the logs of a container
  55. Logs(ctx context.Context, containerName string, request LogsRequest) error
  56. // Delete removes containers
  57. Delete(ctx context.Context, id string, force bool) error
  58. }