backend.go 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package container // import "github.com/docker/docker/api/server/router/container"
  2. import (
  3. "context"
  4. "io"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/api/types/backend"
  7. "github.com/docker/docker/api/types/container"
  8. "github.com/docker/docker/api/types/filters"
  9. containerpkg "github.com/docker/docker/container"
  10. "github.com/docker/docker/pkg/archive"
  11. )
  12. // execBackend includes functions to implement to provide exec functionality.
  13. type execBackend interface {
  14. ContainerExecCreate(name string, config *types.ExecConfig) (string, error)
  15. ContainerExecInspect(id string) (*backend.ExecInspect, error)
  16. ContainerExecResize(name string, height, width int) error
  17. ContainerExecStart(ctx context.Context, name string, options container.ExecStartOptions) error
  18. ExecExists(name string) (bool, error)
  19. }
  20. // copyBackend includes functions to implement to provide container copy functionality.
  21. type copyBackend interface {
  22. ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error)
  23. ContainerCopy(name string, res string) (io.ReadCloser, error)
  24. ContainerExport(ctx context.Context, name string, out io.Writer) error
  25. ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error
  26. ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
  27. }
  28. // stateBackend includes functions to implement to provide container state lifecycle functionality.
  29. type stateBackend interface {
  30. ContainerCreate(ctx context.Context, config types.ContainerCreateConfig) (container.CreateResponse, error)
  31. ContainerKill(name string, signal string) error
  32. ContainerPause(name string) error
  33. ContainerRename(oldName, newName string) error
  34. ContainerResize(name string, height, width int) error
  35. ContainerRestart(ctx context.Context, name string, options container.StopOptions) error
  36. ContainerRm(name string, config *types.ContainerRmConfig) error
  37. ContainerStart(ctx context.Context, name string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
  38. ContainerStop(ctx context.Context, name string, options container.StopOptions) error
  39. ContainerUnpause(name string) error
  40. ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error)
  41. ContainerWait(ctx context.Context, name string, condition containerpkg.WaitCondition) (<-chan containerpkg.StateStatus, error)
  42. }
  43. // monitorBackend includes functions to implement to provide containers monitoring functionality.
  44. type monitorBackend interface {
  45. ContainerChanges(name string) ([]archive.Change, error)
  46. ContainerInspect(ctx context.Context, name string, size bool, version string) (interface{}, error)
  47. ContainerLogs(ctx context.Context, name string, config *types.ContainerLogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
  48. ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
  49. ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
  50. Containers(ctx context.Context, config *types.ContainerListOptions) ([]*types.Container, error)
  51. }
  52. // attachBackend includes function to implement to provide container attaching functionality.
  53. type attachBackend interface {
  54. ContainerAttach(name string, c *backend.ContainerAttachConfig) error
  55. }
  56. // systemBackend includes functions to implement to provide system wide containers functionality
  57. type systemBackend interface {
  58. ContainersPrune(ctx context.Context, pruneFilters filters.Args) (*types.ContainersPruneReport, error)
  59. }
  60. type commitBackend interface {
  61. CreateImageFromContainer(ctx context.Context, name string, config *backend.CreateImageConfig) (imageID string, err error)
  62. }
  63. // Backend is all the methods that need to be implemented to provide container specific functionality.
  64. type Backend interface {
  65. commitBackend
  66. execBackend
  67. copyBackend
  68. stateBackend
  69. monitorBackend
  70. attachBackend
  71. systemBackend
  72. }