api.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright 2020 Docker, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package containers
  14. import (
  15. "context"
  16. "io"
  17. )
  18. // Container represents a created container
  19. type Container struct {
  20. ID string
  21. Status string
  22. Image string
  23. Command string
  24. CPUTime uint64
  25. MemoryUsage uint64
  26. MemoryLimit uint64
  27. PidsCurrent uint64
  28. PidsLimit uint64
  29. Labels []string
  30. Ports []Port
  31. }
  32. // Port represents a published port of a container
  33. type Port struct {
  34. // HostPort is the port number on the host
  35. HostPort uint32
  36. // ContainerPort is the port number inside the container
  37. ContainerPort uint32
  38. // Protocol is the protocol of the port mapping
  39. Protocol string
  40. // HostIP is the host ip to use
  41. HostIP string
  42. }
  43. // ContainerConfig contains the configuration data about a container
  44. type ContainerConfig struct {
  45. // ID uniquely identifies the container
  46. ID string
  47. // Image specifies the iamge reference used for a container
  48. Image string
  49. // Ports provide a list of published ports
  50. Ports []Port
  51. // Labels set labels to the container
  52. Labels map[string]string
  53. // Volumes to be mounted
  54. Volumes []string
  55. }
  56. // LogsRequest contains configuration about a log request
  57. type LogsRequest struct {
  58. Follow bool
  59. Tail string
  60. Writer io.Writer
  61. }
  62. // Service interacts with the underlying container backend
  63. type Service interface {
  64. // List returns all the containers
  65. List(ctx context.Context, all bool) ([]Container, error)
  66. // Stop stops the running container
  67. Stop(ctx context.Context, containerID string, timeout *uint32) error
  68. // Run creates and starts a container
  69. Run(ctx context.Context, config ContainerConfig) error
  70. // Exec executes a command inside a running container
  71. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  72. // Logs returns all the logs of a container
  73. Logs(ctx context.Context, containerName string, request LogsRequest) error
  74. // Delete removes containers
  75. Delete(ctx context.Context, id string, force bool) error
  76. // Inspect get a specific container
  77. Inspect(ctx context.Context, id string) (Container, error)
  78. }