types.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. package types // import "github.com/docker/docker/api/types"
  2. import (
  3. "io"
  4. "os"
  5. "time"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/filters"
  8. "github.com/docker/docker/api/types/image"
  9. "github.com/docker/docker/api/types/mount"
  10. "github.com/docker/docker/api/types/network"
  11. "github.com/docker/docker/api/types/swarm"
  12. "github.com/docker/docker/api/types/volume"
  13. "github.com/docker/go-connections/nat"
  14. )
  15. const (
  16. // MediaTypeRawStream is vendor specific MIME-Type set for raw TTY streams
  17. MediaTypeRawStream = "application/vnd.docker.raw-stream"
  18. // MediaTypeMultiplexedStream is vendor specific MIME-Type set for stdin/stdout/stderr multiplexed streams
  19. MediaTypeMultiplexedStream = "application/vnd.docker.multiplexed-stream"
  20. )
  21. // RootFS returns Image's RootFS description including the layer IDs.
  22. type RootFS struct {
  23. Type string `json:",omitempty"`
  24. Layers []string `json:",omitempty"`
  25. }
  26. // ImageInspect contains response of Engine API:
  27. // GET "/images/{name:.*}/json"
  28. type ImageInspect struct {
  29. // ID is the content-addressable ID of an image.
  30. //
  31. // This identifier is a content-addressable digest calculated from the
  32. // image's configuration (which includes the digests of layers used by
  33. // the image).
  34. //
  35. // Note that this digest differs from the `RepoDigests` below, which
  36. // holds digests of image manifests that reference the image.
  37. ID string `json:"Id"`
  38. // RepoTags is a list of image names/tags in the local image cache that
  39. // reference this image.
  40. //
  41. // Multiple image tags can refer to the same image, and this list may be
  42. // empty if no tags reference the image, in which case the image is
  43. // "untagged", in which case it can still be referenced by its ID.
  44. RepoTags []string
  45. // RepoDigests is a list of content-addressable digests of locally available
  46. // image manifests that the image is referenced from. Multiple manifests can
  47. // refer to the same image.
  48. //
  49. // These digests are usually only available if the image was either pulled
  50. // from a registry, or if the image was pushed to a registry, which is when
  51. // the manifest is generated and its digest calculated.
  52. RepoDigests []string
  53. // Parent is the ID of the parent image.
  54. //
  55. // Depending on how the image was created, this field may be empty and
  56. // is only set for images that were built/created locally. This field
  57. // is empty if the image was pulled from an image registry.
  58. Parent string
  59. // Comment is an optional message that can be set when committing or
  60. // importing the image.
  61. Comment string
  62. // Created is the date and time at which the image was created, formatted in
  63. // RFC 3339 nano-seconds (time.RFC3339Nano).
  64. Created string
  65. // Container is the ID of the container that was used to create the image.
  66. //
  67. // Depending on how the image was created, this field may be empty.
  68. //
  69. // Deprecated: this field is omitted in API v1.45, but kept for backward compatibility.
  70. Container string
  71. // ContainerConfig is an optional field containing the configuration of the
  72. // container that was last committed when creating the image.
  73. //
  74. // Previous versions of Docker builder used this field to store build cache,
  75. // and it is not in active use anymore.
  76. //
  77. // Deprecated: this field is omitted in API v1.45, but kept for backward compatibility.
  78. ContainerConfig *container.Config
  79. // DockerVersion is the version of Docker that was used to build the image.
  80. //
  81. // Depending on how the image was created, this field may be empty.
  82. DockerVersion string
  83. // Author is the name of the author that was specified when committing the
  84. // image, or as specified through MAINTAINER (deprecated) in the Dockerfile.
  85. Author string
  86. Config *container.Config
  87. // Architecture is the hardware CPU architecture that the image runs on.
  88. Architecture string
  89. // Variant is the CPU architecture variant (presently ARM-only).
  90. Variant string `json:",omitempty"`
  91. // OS is the Operating System the image is built to run on.
  92. Os string
  93. // OsVersion is the version of the Operating System the image is built to
  94. // run on (especially for Windows).
  95. OsVersion string `json:",omitempty"`
  96. // Size is the total size of the image including all layers it is composed of.
  97. Size int64
  98. // VirtualSize is the total size of the image including all layers it is
  99. // composed of.
  100. //
  101. // Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
  102. VirtualSize int64 `json:"VirtualSize,omitempty"`
  103. // GraphDriver holds information about the storage driver used to store the
  104. // container's and image's filesystem.
  105. GraphDriver GraphDriverData
  106. // RootFS contains information about the image's RootFS, including the
  107. // layer IDs.
  108. RootFS RootFS
  109. // Metadata of the image in the local cache.
  110. //
  111. // This information is local to the daemon, and not part of the image itself.
  112. Metadata image.Metadata
  113. }
  114. // Container contains response of Engine API:
  115. // GET "/containers/json"
  116. type Container struct {
  117. ID string `json:"Id"`
  118. Names []string
  119. Image string
  120. ImageID string
  121. Command string
  122. Created int64
  123. Ports []Port
  124. SizeRw int64 `json:",omitempty"`
  125. SizeRootFs int64 `json:",omitempty"`
  126. Labels map[string]string
  127. State string
  128. Status string
  129. HostConfig struct {
  130. NetworkMode string `json:",omitempty"`
  131. }
  132. NetworkSettings *SummaryNetworkSettings
  133. Mounts []MountPoint
  134. }
  135. // CopyConfig contains request body of Engine API:
  136. // POST "/containers/"+containerID+"/copy"
  137. type CopyConfig struct {
  138. Resource string
  139. }
  140. // ContainerPathStat is used to encode the header from
  141. // GET "/containers/{name:.*}/archive"
  142. // "Name" is the file or directory name.
  143. type ContainerPathStat struct {
  144. Name string `json:"name"`
  145. Size int64 `json:"size"`
  146. Mode os.FileMode `json:"mode"`
  147. Mtime time.Time `json:"mtime"`
  148. LinkTarget string `json:"linkTarget"`
  149. }
  150. // ContainerStats contains response of Engine API:
  151. // GET "/stats"
  152. type ContainerStats struct {
  153. Body io.ReadCloser `json:"body"`
  154. OSType string `json:"ostype"`
  155. }
  156. // Ping contains response of Engine API:
  157. // GET "/_ping"
  158. type Ping struct {
  159. APIVersion string
  160. OSType string
  161. Experimental bool
  162. BuilderVersion BuilderVersion
  163. // SwarmStatus provides information about the current swarm status of the
  164. // engine, obtained from the "Swarm" header in the API response.
  165. //
  166. // It can be a nil struct if the API version does not provide this header
  167. // in the ping response, or if an error occurred, in which case the client
  168. // should use other ways to get the current swarm status, such as the /swarm
  169. // endpoint.
  170. SwarmStatus *swarm.Status
  171. }
  172. // ComponentVersion describes the version information for a specific component.
  173. type ComponentVersion struct {
  174. Name string
  175. Version string
  176. Details map[string]string `json:",omitempty"`
  177. }
  178. // Version contains response of Engine API:
  179. // GET "/version"
  180. type Version struct {
  181. Platform struct{ Name string } `json:",omitempty"`
  182. Components []ComponentVersion `json:",omitempty"`
  183. // The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility
  184. Version string
  185. APIVersion string `json:"ApiVersion"`
  186. MinAPIVersion string `json:"MinAPIVersion,omitempty"`
  187. GitCommit string
  188. GoVersion string
  189. Os string
  190. Arch string
  191. KernelVersion string `json:",omitempty"`
  192. Experimental bool `json:",omitempty"`
  193. BuildTime string `json:",omitempty"`
  194. }
  195. // ExecStartCheck is a temp struct used by execStart
  196. // Config fields is part of ExecConfig in runconfig package
  197. type ExecStartCheck struct {
  198. // ExecStart will first check if it's detached
  199. Detach bool
  200. // Check if there's a tty
  201. Tty bool
  202. // Terminal size [height, width], unused if Tty == false
  203. ConsoleSize *[2]uint `json:",omitempty"`
  204. }
  205. // HealthcheckResult stores information about a single run of a healthcheck probe
  206. type HealthcheckResult struct {
  207. Start time.Time // Start is the time this check started
  208. End time.Time // End is the time this check ended
  209. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  210. Output string // Output from last check
  211. }
  212. // Health states
  213. const (
  214. NoHealthcheck = "none" // Indicates there is no healthcheck
  215. Starting = "starting" // Starting indicates that the container is not yet ready
  216. Healthy = "healthy" // Healthy indicates that the container is running correctly
  217. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  218. )
  219. // Health stores information about the container's healthcheck results
  220. type Health struct {
  221. Status string // Status is one of Starting, Healthy or Unhealthy
  222. FailingStreak int // FailingStreak is the number of consecutive failures
  223. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  224. }
  225. // ContainerState stores container's running state
  226. // it's part of ContainerJSONBase and will return by "inspect" command
  227. type ContainerState struct {
  228. Status string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
  229. Running bool
  230. Paused bool
  231. Restarting bool
  232. OOMKilled bool
  233. Dead bool
  234. Pid int
  235. ExitCode int
  236. Error string
  237. StartedAt string
  238. FinishedAt string
  239. Health *Health `json:",omitempty"`
  240. }
  241. // ContainerNode stores information about the node that a container
  242. // is running on. It's only used by the Docker Swarm standalone API
  243. type ContainerNode struct {
  244. ID string
  245. IPAddress string `json:"IP"`
  246. Addr string
  247. Name string
  248. Cpus int
  249. Memory int64
  250. Labels map[string]string
  251. }
  252. // ContainerJSONBase contains response of Engine API:
  253. // GET "/containers/{name:.*}/json"
  254. type ContainerJSONBase struct {
  255. ID string `json:"Id"`
  256. Created string
  257. Path string
  258. Args []string
  259. State *ContainerState
  260. Image string
  261. ResolvConfPath string
  262. HostnamePath string
  263. HostsPath string
  264. LogPath string
  265. Node *ContainerNode `json:",omitempty"` // Node is only propagated by Docker Swarm standalone API
  266. Name string
  267. RestartCount int
  268. Driver string
  269. Platform string
  270. MountLabel string
  271. ProcessLabel string
  272. AppArmorProfile string
  273. ExecIDs []string
  274. HostConfig *container.HostConfig
  275. GraphDriver GraphDriverData
  276. SizeRw *int64 `json:",omitempty"`
  277. SizeRootFs *int64 `json:",omitempty"`
  278. }
  279. // ContainerJSON is newly used struct along with MountPoint
  280. type ContainerJSON struct {
  281. *ContainerJSONBase
  282. Mounts []MountPoint
  283. Config *container.Config
  284. NetworkSettings *NetworkSettings
  285. }
  286. // NetworkSettings exposes the network settings in the api
  287. type NetworkSettings struct {
  288. NetworkSettingsBase
  289. DefaultNetworkSettings
  290. Networks map[string]*network.EndpointSettings
  291. }
  292. // SummaryNetworkSettings provides a summary of container's networks
  293. // in /containers/json
  294. type SummaryNetworkSettings struct {
  295. Networks map[string]*network.EndpointSettings
  296. }
  297. // NetworkSettingsBase holds networking state for a container when inspecting it.
  298. type NetworkSettingsBase struct {
  299. Bridge string // Bridge contains the name of the default bridge interface iff it was set through the daemon --bridge flag.
  300. SandboxID string // SandboxID uniquely represents a container's network stack
  301. SandboxKey string // SandboxKey identifies the sandbox
  302. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  303. // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  304. //
  305. // Deprecated: This field is never set and will be removed in a future release.
  306. HairpinMode bool
  307. // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  308. //
  309. // Deprecated: This field is never set and will be removed in a future release.
  310. LinkLocalIPv6Address string
  311. // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  312. //
  313. // Deprecated: This field is never set and will be removed in a future release.
  314. LinkLocalIPv6PrefixLen int
  315. SecondaryIPAddresses []network.Address // Deprecated: This field is never set and will be removed in a future release.
  316. SecondaryIPv6Addresses []network.Address // Deprecated: This field is never set and will be removed in a future release.
  317. }
  318. // DefaultNetworkSettings holds network information
  319. // during the 2 release deprecation period.
  320. // It will be removed in Docker 1.11.
  321. type DefaultNetworkSettings struct {
  322. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  323. Gateway string // Gateway holds the gateway address for the network
  324. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  325. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  326. IPAddress string // IPAddress holds the IPv4 address for the network
  327. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  328. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  329. MacAddress string // MacAddress holds the MAC address for the network
  330. }
  331. // MountPoint represents a mount point configuration inside the container.
  332. // This is used for reporting the mountpoints in use by a container.
  333. type MountPoint struct {
  334. // Type is the type of mount, see `Type<foo>` definitions in
  335. // github.com/docker/docker/api/types/mount.Type
  336. Type mount.Type `json:",omitempty"`
  337. // Name is the name reference to the underlying data defined by `Source`
  338. // e.g., the volume name.
  339. Name string `json:",omitempty"`
  340. // Source is the source location of the mount.
  341. //
  342. // For volumes, this contains the storage location of the volume (within
  343. // `/var/lib/docker/volumes/`). For bind-mounts, and `npipe`, this contains
  344. // the source (host) part of the bind-mount. For `tmpfs` mount points, this
  345. // field is empty.
  346. Source string
  347. // Destination is the path relative to the container root (`/`) where the
  348. // Source is mounted inside the container.
  349. Destination string
  350. // Driver is the volume driver used to create the volume (if it is a volume).
  351. Driver string `json:",omitempty"`
  352. // Mode is a comma separated list of options supplied by the user when
  353. // creating the bind/volume mount.
  354. //
  355. // The default is platform-specific (`"z"` on Linux, empty on Windows).
  356. Mode string
  357. // RW indicates whether the mount is mounted writable (read-write).
  358. RW bool
  359. // Propagation describes how mounts are propagated from the host into the
  360. // mount point, and vice-versa. Refer to the Linux kernel documentation
  361. // for details:
  362. // https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
  363. //
  364. // This field is not used on Windows.
  365. Propagation mount.Propagation
  366. }
  367. // NetworkResource is the body of the "get network" http response message
  368. type NetworkResource struct {
  369. Name string // Name is the requested name of the network
  370. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  371. Created time.Time // Created is the time the network created
  372. Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
  373. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  374. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  375. IPAM network.IPAM // IPAM is the network's IP Address Management
  376. Internal bool // Internal represents if the network is used internal only
  377. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  378. Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
  379. ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
  380. ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
  381. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  382. Options map[string]string // Options holds the network specific options to use for when creating the network
  383. Labels map[string]string // Labels holds metadata specific to the network being created
  384. Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
  385. Services map[string]network.ServiceInfo `json:",omitempty"`
  386. }
  387. // EndpointResource contains network resources allocated and used for a container in a network
  388. type EndpointResource struct {
  389. Name string
  390. EndpointID string
  391. MacAddress string
  392. IPv4Address string
  393. IPv6Address string
  394. }
  395. // NetworkCreate is the expected body of the "create network" http request message
  396. type NetworkCreate struct {
  397. // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
  398. // package to older daemons.
  399. CheckDuplicate bool `json:",omitempty"`
  400. Driver string
  401. Scope string
  402. EnableIPv6 bool
  403. IPAM *network.IPAM
  404. Internal bool
  405. Attachable bool
  406. Ingress bool
  407. ConfigOnly bool
  408. ConfigFrom *network.ConfigReference
  409. Options map[string]string
  410. Labels map[string]string
  411. }
  412. // NetworkCreateRequest is the request message sent to the server for network create call.
  413. type NetworkCreateRequest struct {
  414. NetworkCreate
  415. Name string
  416. }
  417. // NetworkCreateResponse is the response message sent by the server for network create call
  418. type NetworkCreateResponse struct {
  419. ID string `json:"Id"`
  420. Warning string
  421. }
  422. // NetworkConnect represents the data to be used to connect a container to the network
  423. type NetworkConnect struct {
  424. Container string
  425. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  426. }
  427. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  428. type NetworkDisconnect struct {
  429. Container string
  430. Force bool
  431. }
  432. // NetworkInspectOptions holds parameters to inspect network
  433. type NetworkInspectOptions struct {
  434. Scope string
  435. Verbose bool
  436. }
  437. // DiskUsageObject represents an object type used for disk usage query filtering.
  438. type DiskUsageObject string
  439. const (
  440. // ContainerObject represents a container DiskUsageObject.
  441. ContainerObject DiskUsageObject = "container"
  442. // ImageObject represents an image DiskUsageObject.
  443. ImageObject DiskUsageObject = "image"
  444. // VolumeObject represents a volume DiskUsageObject.
  445. VolumeObject DiskUsageObject = "volume"
  446. // BuildCacheObject represents a build-cache DiskUsageObject.
  447. BuildCacheObject DiskUsageObject = "build-cache"
  448. )
  449. // DiskUsageOptions holds parameters for system disk usage query.
  450. type DiskUsageOptions struct {
  451. // Types specifies what object types to include in the response. If empty,
  452. // all object types are returned.
  453. Types []DiskUsageObject
  454. }
  455. // DiskUsage contains response of Engine API:
  456. // GET "/system/df"
  457. type DiskUsage struct {
  458. LayersSize int64
  459. Images []*image.Summary
  460. Containers []*Container
  461. Volumes []*volume.Volume
  462. BuildCache []*BuildCache
  463. BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.
  464. }
  465. // ContainersPruneReport contains the response for Engine API:
  466. // POST "/containers/prune"
  467. type ContainersPruneReport struct {
  468. ContainersDeleted []string
  469. SpaceReclaimed uint64
  470. }
  471. // VolumesPruneReport contains the response for Engine API:
  472. // POST "/volumes/prune"
  473. type VolumesPruneReport struct {
  474. VolumesDeleted []string
  475. SpaceReclaimed uint64
  476. }
  477. // ImagesPruneReport contains the response for Engine API:
  478. // POST "/images/prune"
  479. type ImagesPruneReport struct {
  480. ImagesDeleted []image.DeleteResponse
  481. SpaceReclaimed uint64
  482. }
  483. // BuildCachePruneReport contains the response for Engine API:
  484. // POST "/build/prune"
  485. type BuildCachePruneReport struct {
  486. CachesDeleted []string
  487. SpaceReclaimed uint64
  488. }
  489. // NetworksPruneReport contains the response for Engine API:
  490. // POST "/networks/prune"
  491. type NetworksPruneReport struct {
  492. NetworksDeleted []string
  493. }
  494. // SecretCreateResponse contains the information returned to a client
  495. // on the creation of a new secret.
  496. type SecretCreateResponse struct {
  497. // ID is the id of the created secret.
  498. ID string
  499. }
  500. // SecretListOptions holds parameters to list secrets
  501. type SecretListOptions struct {
  502. Filters filters.Args
  503. }
  504. // ConfigCreateResponse contains the information returned to a client
  505. // on the creation of a new config.
  506. type ConfigCreateResponse struct {
  507. // ID is the id of the created config.
  508. ID string
  509. }
  510. // ConfigListOptions holds parameters to list configs
  511. type ConfigListOptions struct {
  512. Filters filters.Args
  513. }
  514. // PushResult contains the tag, manifest digest, and manifest size from the
  515. // push. It's used to signal this information to the trust code in the client
  516. // so it can sign the manifest if necessary.
  517. type PushResult struct {
  518. Tag string
  519. Digest string
  520. Size int
  521. }
  522. // BuildResult contains the image id of a successful build
  523. type BuildResult struct {
  524. ID string
  525. }
  526. // BuildCache contains information about a build cache record.
  527. type BuildCache struct {
  528. // ID is the unique ID of the build cache record.
  529. ID string
  530. // Parent is the ID of the parent build cache record.
  531. //
  532. // Deprecated: deprecated in API v1.42 and up, as it was deprecated in BuildKit; use Parents instead.
  533. Parent string `json:"Parent,omitempty"`
  534. // Parents is the list of parent build cache record IDs.
  535. Parents []string `json:" Parents,omitempty"`
  536. // Type is the cache record type.
  537. Type string
  538. // Description is a description of the build-step that produced the build cache.
  539. Description string
  540. // InUse indicates if the build cache is in use.
  541. InUse bool
  542. // Shared indicates if the build cache is shared.
  543. Shared bool
  544. // Size is the amount of disk space used by the build cache (in bytes).
  545. Size int64
  546. // CreatedAt is the date and time at which the build cache was created.
  547. CreatedAt time.Time
  548. // LastUsedAt is the date and time at which the build cache was last used.
  549. LastUsedAt *time.Time
  550. UsageCount int
  551. }
  552. // BuildCachePruneOptions hold parameters to prune the build cache
  553. type BuildCachePruneOptions struct {
  554. All bool
  555. KeepStorage int64
  556. Filters filters.Args
  557. }