client.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. package types // import "github.com/docker/docker/api/types"
  2. import (
  3. "bufio"
  4. "io"
  5. "net"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/filters"
  8. "github.com/docker/go-units"
  9. specs "github.com/opencontainers/image-spec/specs-go/v1"
  10. )
  11. // CheckpointCreateOptions holds parameters to create a checkpoint from a container
  12. type CheckpointCreateOptions struct {
  13. CheckpointID string
  14. CheckpointDir string
  15. Exit bool
  16. }
  17. // CheckpointListOptions holds parameters to list checkpoints for a container
  18. type CheckpointListOptions struct {
  19. CheckpointDir string
  20. }
  21. // CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
  22. type CheckpointDeleteOptions struct {
  23. CheckpointID string
  24. CheckpointDir string
  25. }
  26. // ContainerAttachOptions holds parameters to attach to a container.
  27. type ContainerAttachOptions struct {
  28. Stream bool
  29. Stdin bool
  30. Stdout bool
  31. Stderr bool
  32. DetachKeys string
  33. Logs bool
  34. }
  35. // ContainerCommitOptions holds parameters to commit changes into a container.
  36. type ContainerCommitOptions struct {
  37. Reference string
  38. Comment string
  39. Author string
  40. Changes []string
  41. Pause bool
  42. Config *container.Config
  43. }
  44. // ContainerExecInspect holds information returned by exec inspect.
  45. type ContainerExecInspect struct {
  46. ExecID string
  47. ContainerID string
  48. Running bool
  49. ExitCode int
  50. Pid int
  51. }
  52. // ContainerListOptions holds parameters to list containers with.
  53. type ContainerListOptions struct {
  54. Quiet bool
  55. Size bool
  56. All bool
  57. Latest bool
  58. Since string
  59. Before string
  60. Limit int
  61. Filters filters.Args
  62. }
  63. // ContainerLogsOptions holds parameters to filter logs with.
  64. type ContainerLogsOptions struct {
  65. ShowStdout bool
  66. ShowStderr bool
  67. Since string
  68. Until string
  69. Timestamps bool
  70. Follow bool
  71. Tail string
  72. Details bool
  73. }
  74. // ContainerRemoveOptions holds parameters to remove containers.
  75. type ContainerRemoveOptions struct {
  76. RemoveVolumes bool
  77. RemoveLinks bool
  78. Force bool
  79. }
  80. // ContainerStartOptions holds parameters to start containers.
  81. type ContainerStartOptions struct {
  82. CheckpointID string
  83. CheckpointDir string
  84. }
  85. // CopyToContainerOptions holds information
  86. // about files to copy into a container
  87. type CopyToContainerOptions struct {
  88. AllowOverwriteDirWithFile bool
  89. CopyUIDGID bool
  90. }
  91. // EventsOptions holds parameters to filter events with.
  92. type EventsOptions struct {
  93. Since string
  94. Until string
  95. Filters filters.Args
  96. }
  97. // NetworkListOptions holds parameters to filter the list of networks with.
  98. type NetworkListOptions struct {
  99. Filters filters.Args
  100. }
  101. // HijackedResponse holds connection information for a hijacked request.
  102. type HijackedResponse struct {
  103. Conn net.Conn
  104. Reader *bufio.Reader
  105. }
  106. // Close closes the hijacked connection and reader.
  107. func (h *HijackedResponse) Close() {
  108. h.Conn.Close()
  109. }
  110. // CloseWriter is an interface that implements structs
  111. // that close input streams to prevent from writing.
  112. type CloseWriter interface {
  113. CloseWrite() error
  114. }
  115. // CloseWrite closes a readWriter for writing.
  116. func (h *HijackedResponse) CloseWrite() error {
  117. if conn, ok := h.Conn.(CloseWriter); ok {
  118. return conn.CloseWrite()
  119. }
  120. return nil
  121. }
  122. // ImageBuildOptions holds the information
  123. // necessary to build images.
  124. type ImageBuildOptions struct {
  125. Tags []string
  126. SuppressOutput bool
  127. RemoteContext string
  128. NoCache bool
  129. Remove bool
  130. ForceRemove bool
  131. PullParent bool
  132. Isolation container.Isolation
  133. CPUSetCPUs string
  134. CPUSetMems string
  135. CPUShares int64
  136. CPUQuota int64
  137. CPUPeriod int64
  138. Memory int64
  139. MemorySwap int64
  140. CgroupParent string
  141. NetworkMode string
  142. ShmSize int64
  143. Dockerfile string
  144. Ulimits []*units.Ulimit
  145. // BuildArgs needs to be a *string instead of just a string so that
  146. // we can tell the difference between "" (empty string) and no value
  147. // at all (nil). See the parsing of buildArgs in
  148. // api/server/router/build/build_routes.go for even more info.
  149. BuildArgs map[string]*string
  150. AuthConfigs map[string]AuthConfig
  151. Context io.Reader
  152. Labels map[string]string
  153. // squash the resulting image's layers to the parent
  154. // preserves the original image and creates a new one from the parent with all
  155. // the changes applied to a single layer
  156. Squash bool
  157. // CacheFrom specifies images that are used for matching cache. Images
  158. // specified here do not need to have a valid parent chain to match cache.
  159. CacheFrom []string
  160. SecurityOpt []string
  161. ExtraHosts []string // List of extra hosts
  162. Target string
  163. SessionID string
  164. Platform *specs.Platform
  165. // Version specifies the version of the unerlying builder to use
  166. Version BuilderVersion
  167. // BuildID is an optional identifier that can be passed together with the
  168. // build request. The same identifier can be used to gracefully cancel the
  169. // build with the cancel request.
  170. BuildID string
  171. }
  172. // BuilderVersion sets the version of underlying builder to use
  173. type BuilderVersion string
  174. const (
  175. // BuilderV1 is the first generation builder in docker daemon
  176. BuilderV1 BuilderVersion = "1"
  177. // BuilderBuildKit is builder based on moby/buildkit project
  178. BuilderBuildKit = "2"
  179. )
  180. // ImageBuildResponse holds information
  181. // returned by a server after building
  182. // an image.
  183. type ImageBuildResponse struct {
  184. Body io.ReadCloser
  185. OSType string
  186. }
  187. // ImageCreateOptions holds information to create images.
  188. type ImageCreateOptions struct {
  189. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
  190. Platform string // Platform is the target platform of the image if it needs to be pulled from the registry.
  191. }
  192. // ImageImportSource holds source information for ImageImport
  193. type ImageImportSource struct {
  194. Source io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
  195. SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
  196. }
  197. // ImageImportOptions holds information to import images from the client host.
  198. type ImageImportOptions struct {
  199. Tag string // Tag is the name to tag this image with. This attribute is deprecated.
  200. Message string // Message is the message to tag the image with
  201. Changes []string // Changes are the raw changes to apply to this image
  202. Platform string // Platform is the target platform of the image
  203. }
  204. // ImageListOptions holds parameters to filter the list of images with.
  205. type ImageListOptions struct {
  206. All bool
  207. Filters filters.Args
  208. }
  209. // ImageLoadResponse returns information to the client about a load process.
  210. type ImageLoadResponse struct {
  211. // Body must be closed to avoid a resource leak
  212. Body io.ReadCloser
  213. JSON bool
  214. }
  215. // ImagePullOptions holds information to pull images.
  216. type ImagePullOptions struct {
  217. All bool
  218. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  219. PrivilegeFunc RequestPrivilegeFunc
  220. Platform string
  221. }
  222. // RequestPrivilegeFunc is a function interface that
  223. // clients can supply to retry operations after
  224. // getting an authorization error.
  225. // This function returns the registry authentication
  226. // header value in base 64 format, or an error
  227. // if the privilege request fails.
  228. type RequestPrivilegeFunc func() (string, error)
  229. //ImagePushOptions holds information to push images.
  230. type ImagePushOptions ImagePullOptions
  231. // ImageRemoveOptions holds parameters to remove images.
  232. type ImageRemoveOptions struct {
  233. Force bool
  234. PruneChildren bool
  235. }
  236. // ImageSearchOptions holds parameters to search images with.
  237. type ImageSearchOptions struct {
  238. RegistryAuth string
  239. PrivilegeFunc RequestPrivilegeFunc
  240. Filters filters.Args
  241. Limit int
  242. }
  243. // ResizeOptions holds parameters to resize a tty.
  244. // It can be used to resize container ttys and
  245. // exec process ttys too.
  246. type ResizeOptions struct {
  247. Height uint
  248. Width uint
  249. }
  250. // NodeListOptions holds parameters to list nodes with.
  251. type NodeListOptions struct {
  252. Filters filters.Args
  253. }
  254. // NodeRemoveOptions holds parameters to remove nodes with.
  255. type NodeRemoveOptions struct {
  256. Force bool
  257. }
  258. // ServiceCreateOptions contains the options to use when creating a service.
  259. type ServiceCreateOptions struct {
  260. // EncodedRegistryAuth is the encoded registry authorization credentials to
  261. // use when updating the service.
  262. //
  263. // This field follows the format of the X-Registry-Auth header.
  264. EncodedRegistryAuth string
  265. // QueryRegistry indicates whether the service update requires
  266. // contacting a registry. A registry may be contacted to retrieve
  267. // the image digest and manifest, which in turn can be used to update
  268. // platform or other information about the service.
  269. QueryRegistry bool
  270. }
  271. // ServiceCreateResponse contains the information returned to a client
  272. // on the creation of a new service.
  273. type ServiceCreateResponse struct {
  274. // ID is the ID of the created service.
  275. ID string
  276. // Warnings is a set of non-fatal warning messages to pass on to the user.
  277. Warnings []string `json:",omitempty"`
  278. }
  279. // Values for RegistryAuthFrom in ServiceUpdateOptions
  280. const (
  281. RegistryAuthFromSpec = "spec"
  282. RegistryAuthFromPreviousSpec = "previous-spec"
  283. )
  284. // ServiceUpdateOptions contains the options to be used for updating services.
  285. type ServiceUpdateOptions struct {
  286. // EncodedRegistryAuth is the encoded registry authorization credentials to
  287. // use when updating the service.
  288. //
  289. // This field follows the format of the X-Registry-Auth header.
  290. EncodedRegistryAuth string
  291. // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
  292. // into this field. While it does open API users up to racy writes, most
  293. // users may not need that level of consistency in practice.
  294. // RegistryAuthFrom specifies where to find the registry authorization
  295. // credentials if they are not given in EncodedRegistryAuth. Valid
  296. // values are "spec" and "previous-spec".
  297. RegistryAuthFrom string
  298. // Rollback indicates whether a server-side rollback should be
  299. // performed. When this is set, the provided spec will be ignored.
  300. // The valid values are "previous" and "none". An empty value is the
  301. // same as "none".
  302. Rollback string
  303. // QueryRegistry indicates whether the service update requires
  304. // contacting a registry. A registry may be contacted to retrieve
  305. // the image digest and manifest, which in turn can be used to update
  306. // platform or other information about the service.
  307. QueryRegistry bool
  308. }
  309. // ServiceListOptions holds parameters to list services with.
  310. type ServiceListOptions struct {
  311. Filters filters.Args
  312. }
  313. // ServiceInspectOptions holds parameters related to the "service inspect"
  314. // operation.
  315. type ServiceInspectOptions struct {
  316. InsertDefaults bool
  317. }
  318. // TaskListOptions holds parameters to list tasks with.
  319. type TaskListOptions struct {
  320. Filters filters.Args
  321. }
  322. // PluginRemoveOptions holds parameters to remove plugins.
  323. type PluginRemoveOptions struct {
  324. Force bool
  325. }
  326. // PluginEnableOptions holds parameters to enable plugins.
  327. type PluginEnableOptions struct {
  328. Timeout int
  329. }
  330. // PluginDisableOptions holds parameters to disable plugins.
  331. type PluginDisableOptions struct {
  332. Force bool
  333. }
  334. // PluginInstallOptions holds parameters to install a plugin.
  335. type PluginInstallOptions struct {
  336. Disabled bool
  337. AcceptAllPermissions bool
  338. RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
  339. RemoteRef string // RemoteRef is the plugin name on the registry
  340. PrivilegeFunc RequestPrivilegeFunc
  341. AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
  342. Args []string
  343. }
  344. // SwarmUnlockKeyResponse contains the response for Engine API:
  345. // GET /swarm/unlockkey
  346. type SwarmUnlockKeyResponse struct {
  347. // UnlockKey is the unlock key in ASCII-armored format.
  348. UnlockKey string
  349. }
  350. // PluginCreateOptions hold all options to plugin create.
  351. type PluginCreateOptions struct {
  352. RepoName string
  353. }