types.go 22 KB

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