1
0

api.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. RestartPolicyCondition string
  35. }
  36. // Port represents a published port of a container
  37. type Port struct {
  38. // HostPort is the port number on the host
  39. HostPort uint32
  40. // ContainerPort is the port number inside the container
  41. ContainerPort uint32
  42. // Protocol is the protocol of the port mapping
  43. Protocol string
  44. // HostIP is the host ip to use
  45. HostIP string
  46. }
  47. // ContainerConfig contains the configuration data about a container
  48. type ContainerConfig struct {
  49. // ID uniquely identifies the container
  50. ID string
  51. // Image specifies the iamge reference used for a container
  52. Image string
  53. // Ports provide a list of published ports
  54. Ports []Port
  55. // Labels set labels to the container
  56. Labels map[string]string
  57. // Volumes to be mounted
  58. Volumes []string
  59. // Memlimit
  60. MemLimit formatter.MemBytes
  61. // CPUlimit
  62. CPULimit float64
  63. // Environment variables
  64. Environment []string
  65. // Restart policy condition
  66. RestartPolicyCondition string
  67. }
  68. // ExecRequest contaiens configuration about an exec request
  69. type ExecRequest struct {
  70. Stdin io.Reader
  71. Stdout io.Writer
  72. Stderr io.Writer
  73. Command string
  74. Interactive bool
  75. Tty bool
  76. }
  77. // LogsRequest contains configuration about a log request
  78. type LogsRequest struct {
  79. Follow bool
  80. Tail string
  81. Width int
  82. Writer io.Writer
  83. }
  84. // Service interacts with the underlying container backend
  85. type Service interface {
  86. // List returns all the containers
  87. List(ctx context.Context, all bool) ([]Container, error)
  88. // Stop stops the running container
  89. Stop(ctx context.Context, containerID string, timeout *uint32) error
  90. // Run creates and starts a container
  91. Run(ctx context.Context, config ContainerConfig) error
  92. // Exec executes a command inside a running container
  93. Exec(ctx context.Context, containerName string, request ExecRequest) error
  94. // Logs returns all the logs of a container
  95. Logs(ctx context.Context, containerName string, request LogsRequest) error
  96. // Delete removes containers
  97. Delete(ctx context.Context, id string, force bool) error
  98. // Inspect get a specific container
  99. Inspect(ctx context.Context, id string) (Container, error)
  100. }