backend.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ContainerExport(ctx context.Context, name string, out io.Writer) error
  24. ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error
  25. ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
  26. }
  27. // stateBackend includes functions to implement to provide container state lifecycle functionality.
  28. type stateBackend interface {
  29. ContainerCreate(ctx context.Context, config backend.ContainerCreateConfig) (container.CreateResponse, error)
  30. ContainerKill(name string, signal string) error
  31. ContainerPause(name string) error
  32. ContainerRename(oldName, newName string) error
  33. ContainerResize(name string, height, width int) error
  34. ContainerRestart(ctx context.Context, name string, options container.StopOptions) error
  35. ContainerRm(name string, config *backend.ContainerRmConfig) error
  36. ContainerStart(ctx context.Context, name string, checkpoint string, checkpointDir string) error
  37. ContainerStop(ctx context.Context, name string, options container.StopOptions) error
  38. ContainerUnpause(name string) error
  39. ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error)
  40. ContainerWait(ctx context.Context, name string, condition containerpkg.WaitCondition) (<-chan containerpkg.StateStatus, error)
  41. }
  42. // monitorBackend includes functions to implement to provide containers monitoring functionality.
  43. type monitorBackend interface {
  44. ContainerChanges(ctx context.Context, name string) ([]archive.Change, error)
  45. ContainerInspect(ctx context.Context, name string, size bool, version string) (interface{}, error)
  46. ContainerLogs(ctx context.Context, name string, config *container.LogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
  47. ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
  48. ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
  49. Containers(ctx context.Context, config *container.ListOptions) ([]*types.Container, error)
  50. }
  51. // attachBackend includes function to implement to provide container attaching functionality.
  52. type attachBackend interface {
  53. ContainerAttach(name string, c *backend.ContainerAttachConfig) error
  54. }
  55. // systemBackend includes functions to implement to provide system wide containers functionality
  56. type systemBackend interface {
  57. ContainersPrune(ctx context.Context, pruneFilters filters.Args) (*types.ContainersPruneReport, error)
  58. }
  59. type commitBackend interface {
  60. CreateImageFromContainer(ctx context.Context, name string, config *backend.CreateImageConfig) (imageID string, err error)
  61. }
  62. // Backend is all the methods that need to be implemented to provide container specific functionality.
  63. type Backend interface {
  64. commitBackend
  65. execBackend
  66. copyBackend
  67. stateBackend
  68. monitorBackend
  69. attachBackend
  70. systemBackend
  71. }