api.go 2.7 KB

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