api.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. "github.com/docker/api/formatter"
  18. )
  19. // Container represents a created container
  20. type Container struct {
  21. ID string
  22. Status string
  23. Image string
  24. Command string
  25. CPUTime uint64
  26. CPULimit float64
  27. MemoryUsage uint64
  28. MemoryLimit uint64
  29. PidsCurrent uint64
  30. PidsLimit uint64
  31. Labels []string
  32. Ports []Port
  33. Platform string
  34. }
  35. // Port represents a published port of a container
  36. type Port struct {
  37. // HostPort is the port number on the host
  38. HostPort uint32
  39. // ContainerPort is the port number inside the container
  40. ContainerPort uint32
  41. // Protocol is the protocol of the port mapping
  42. Protocol string
  43. // HostIP is the host ip to use
  44. HostIP string
  45. }
  46. // ContainerConfig contains the configuration data about a container
  47. type ContainerConfig struct {
  48. // ID uniquely identifies the container
  49. ID string
  50. // Image specifies the iamge reference used for a container
  51. Image string
  52. // Ports provide a list of published ports
  53. Ports []Port
  54. // Labels set labels to the container
  55. Labels map[string]string
  56. // Volumes to be mounted
  57. Volumes []string
  58. // Memlimit
  59. MemLimit formatter.MemBytes
  60. // CPUlimit
  61. CPULimit float64
  62. // Environment variables
  63. Environment []string
  64. }
  65. // LogsRequest contains configuration about a log request
  66. type LogsRequest struct {
  67. Follow bool
  68. Tail string
  69. Width int
  70. Writer io.Writer
  71. }
  72. // Service interacts with the underlying container backend
  73. type Service interface {
  74. // List returns all the containers
  75. List(ctx context.Context, all bool) ([]Container, error)
  76. // Stop stops the running container
  77. Stop(ctx context.Context, containerID string, timeout *uint32) error
  78. // Run creates and starts a container
  79. Run(ctx context.Context, config ContainerConfig) error
  80. // Exec executes a command inside a running container
  81. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  82. // Logs returns all the logs of a container
  83. Logs(ctx context.Context, containerName string, request LogsRequest) error
  84. // Delete removes containers
  85. Delete(ctx context.Context, id string, force bool) error
  86. // Inspect get a specific container
  87. Inspect(ctx context.Context, id string) (Container, error)
  88. }