api.go 1.9 KB

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