client.go 13 KB

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