api.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // ContainerService interacts with the underlying container backend
  36. type ContainerService interface {
  37. // List returns all the containers
  38. List(ctx context.Context) ([]Container, error)
  39. // Run creates and starts a container
  40. Run(ctx context.Context, config ContainerConfig) error
  41. // Exec executes a command inside a running container
  42. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  43. // Logs returns all the logs of a container
  44. Logs(ctx context.Context, name string, writer io.Writer, follow bool) error
  45. }