api.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. Writer io.Writer
  70. }
  71. // Service interacts with the underlying container backend
  72. type Service interface {
  73. // List returns all the containers
  74. List(ctx context.Context, all bool) ([]Container, error)
  75. // Stop stops the running container
  76. Stop(ctx context.Context, containerID string, timeout *uint32) error
  77. // Run creates and starts a container
  78. Run(ctx context.Context, config ContainerConfig) error
  79. // Exec executes a command inside a running container
  80. Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
  81. // Logs returns all the logs of a container
  82. Logs(ctx context.Context, containerName string, request LogsRequest) error
  83. // Delete removes containers
  84. Delete(ctx context.Context, id string, force bool) error
  85. // Inspect get a specific container
  86. Inspect(ctx context.Context, id string) (Container, error)
  87. }