types.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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/mount"
  9. "github.com/docker/docker/api/types/network"
  10. "github.com/docker/docker/api/types/swarm"
  11. "github.com/docker/docker/api/types/volume"
  12. "github.com/docker/go-connections/nat"
  13. )
  14. const (
  15. // MediaTypeRawStream is vendor specific MIME-Type set for raw TTY streams
  16. MediaTypeRawStream = "application/vnd.docker.raw-stream"
  17. // MediaTypeMultiplexedStream is vendor specific MIME-Type set for stdin/stdout/stderr multiplexed streams
  18. MediaTypeMultiplexedStream = "application/vnd.docker.multiplexed-stream"
  19. )
  20. // RootFS returns Image's RootFS description including the layer IDs.
  21. type RootFS struct {
  22. Type string `json:",omitempty"`
  23. Layers []string `json:",omitempty"`
  24. }
  25. // ImageInspect contains response of Engine API:
  26. // GET "/images/{name:.*}/json"
  27. type ImageInspect struct {
  28. // ID is the content-addressable ID of an image.
  29. //
  30. // This identifier is a content-addressable digest calculated from the
  31. // image's configuration (which includes the digests of layers used by
  32. // the image).
  33. //
  34. // Note that this digest differs from the `RepoDigests` below, which
  35. // holds digests of image manifests that reference the image.
  36. ID string `json:"Id"`
  37. // RepoTags is a list of image names/tags in the local image cache that
  38. // reference this image.
  39. //
  40. // Multiple image tags can refer to the same image, and this list may be
  41. // empty if no tags reference the image, in which case the image is
  42. // "untagged", in which case it can still be referenced by its ID.
  43. RepoTags []string
  44. // RepoDigests is a list of content-addressable digests of locally available
  45. // image manifests that the image is referenced from. Multiple manifests can
  46. // refer to the same image.
  47. //
  48. // These digests are usually only available if the image was either pulled
  49. // from a registry, or if the image was pushed to a registry, which is when
  50. // the manifest is generated and its digest calculated.
  51. RepoDigests []string
  52. // Parent is the ID of the parent image.
  53. //
  54. // Depending on how the image was created, this field may be empty and
  55. // is only set for images that were built/created locally. This field
  56. // is empty if the image was pulled from an image registry.
  57. Parent string
  58. // Comment is an optional message that can be set when committing or
  59. // importing the image.
  60. Comment string
  61. // Created is the date and time at which the image was created, formatted in
  62. // RFC 3339 nano-seconds (time.RFC3339Nano).
  63. Created string
  64. // Container is the ID of the container that was used to create the image.
  65. //
  66. // Depending on how the image was created, this field may be empty.
  67. Container string
  68. // ContainerConfig is an optional field containing the configuration of the
  69. // container that was last committed when creating the image.
  70. //
  71. // Previous versions of Docker builder used this field to store build cache,
  72. // and it is not in active use anymore.
  73. ContainerConfig *container.Config
  74. // DockerVersion is the version of Docker that was used to build the image.
  75. //
  76. // Depending on how the image was created, this field may be empty.
  77. DockerVersion string
  78. // Author is the name of the author that was specified when committing the
  79. // image, or as specified through MAINTAINER (deprecated) in the Dockerfile.
  80. Author string
  81. Config *container.Config
  82. // Architecture is the hardware CPU architecture that the image runs on.
  83. Architecture string
  84. // Variant is the CPU architecture variant (presently ARM-only).
  85. Variant string `json:",omitempty"`
  86. // OS is the Operating System the image is built to run on.
  87. Os string
  88. // OsVersion is the version of the Operating System the image is built to
  89. // run on (especially for Windows).
  90. OsVersion string `json:",omitempty"`
  91. // Size is the total size of the image including all layers it is composed of.
  92. Size int64
  93. // VirtualSize is the total size of the image including all layers it is
  94. // composed of.
  95. //
  96. // Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
  97. VirtualSize int64 `json:"VirtualSize,omitempty"`
  98. // GraphDriver holds information about the storage driver used to store the
  99. // container's and image's filesystem.
  100. GraphDriver GraphDriverData
  101. // RootFS contains information about the image's RootFS, including the
  102. // layer IDs.
  103. RootFS RootFS
  104. // Metadata of the image in the local cache.
  105. //
  106. // This information is local to the daemon, and not part of the image itself.
  107. Metadata ImageMetadata
  108. }
  109. // ImageMetadata contains engine-local data about the image
  110. type ImageMetadata struct {
  111. // LastTagTime is the date and time at which the image was last tagged.
  112. LastTagTime time.Time `json:",omitempty"`
  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 basic information about networks
  298. type NetworkSettingsBase struct {
  299. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  300. SandboxID string // SandboxID uniquely represents a container's network stack
  301. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  302. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  303. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  304. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  305. SandboxKey string // SandboxKey identifies the sandbox
  306. SecondaryIPAddresses []network.Address
  307. SecondaryIPv6Addresses []network.Address
  308. }
  309. // DefaultNetworkSettings holds network information
  310. // during the 2 release deprecation period.
  311. // It will be removed in Docker 1.11.
  312. type DefaultNetworkSettings struct {
  313. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  314. Gateway string // Gateway holds the gateway address for the network
  315. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  316. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  317. IPAddress string // IPAddress holds the IPv4 address for the network
  318. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  319. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  320. MacAddress string // MacAddress holds the MAC address for the network
  321. }
  322. // MountPoint represents a mount point configuration inside the container.
  323. // This is used for reporting the mountpoints in use by a container.
  324. type MountPoint struct {
  325. // Type is the type of mount, see `Type<foo>` definitions in
  326. // github.com/docker/docker/api/types/mount.Type
  327. Type mount.Type `json:",omitempty"`
  328. // Name is the name reference to the underlying data defined by `Source`
  329. // e.g., the volume name.
  330. Name string `json:",omitempty"`
  331. // Source is the source location of the mount.
  332. //
  333. // For volumes, this contains the storage location of the volume (within
  334. // `/var/lib/docker/volumes/`). For bind-mounts, and `npipe`, this contains
  335. // the source (host) part of the bind-mount. For `tmpfs` mount points, this
  336. // field is empty.
  337. Source string
  338. // Destination is the path relative to the container root (`/`) where the
  339. // Source is mounted inside the container.
  340. Destination string
  341. // Driver is the volume driver used to create the volume (if it is a volume).
  342. Driver string `json:",omitempty"`
  343. // Mode is a comma separated list of options supplied by the user when
  344. // creating the bind/volume mount.
  345. //
  346. // The default is platform-specific (`"z"` on Linux, empty on Windows).
  347. Mode string
  348. // RW indicates whether the mount is mounted writable (read-write).
  349. RW bool
  350. // Propagation describes how mounts are propagated from the host into the
  351. // mount point, and vice-versa. Refer to the Linux kernel documentation
  352. // for details:
  353. // https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
  354. //
  355. // This field is not used on Windows.
  356. Propagation mount.Propagation
  357. }
  358. // NetworkResource is the body of the "get network" http response message
  359. type NetworkResource struct {
  360. Name string // Name is the requested name of the network
  361. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  362. Created time.Time // Created is the time the network created
  363. Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
  364. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  365. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  366. IPAM network.IPAM // IPAM is the network's IP Address Management
  367. Internal bool // Internal represents if the network is used internal only
  368. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  369. Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
  370. ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
  371. 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.
  372. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  373. Options map[string]string // Options holds the network specific options to use for when creating the network
  374. Labels map[string]string // Labels holds metadata specific to the network being created
  375. Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
  376. Services map[string]network.ServiceInfo `json:",omitempty"`
  377. }
  378. // EndpointResource contains network resources allocated and used for a container in a network
  379. type EndpointResource struct {
  380. Name string
  381. EndpointID string
  382. MacAddress string
  383. IPv4Address string
  384. IPv6Address string
  385. }
  386. // NetworkCreate is the expected body of the "create network" http request message
  387. type NetworkCreate struct {
  388. // Check for networks with duplicate names.
  389. // Network is primarily keyed based on a random ID and not on the name.
  390. // Network name is strictly a user-friendly alias to the network
  391. // which is uniquely identified using ID.
  392. // And there is no guaranteed way to check for duplicates.
  393. // Option CheckDuplicate is there to provide a best effort checking of any networks
  394. // which has the same name but it is not guaranteed to catch all name collisions.
  395. CheckDuplicate bool
  396. Driver string
  397. Scope string
  398. EnableIPv6 bool
  399. IPAM *network.IPAM
  400. Internal bool
  401. Attachable bool
  402. Ingress bool
  403. ConfigOnly bool
  404. ConfigFrom *network.ConfigReference
  405. Options map[string]string
  406. Labels map[string]string
  407. }
  408. // NetworkCreateRequest is the request message sent to the server for network create call.
  409. type NetworkCreateRequest struct {
  410. NetworkCreate
  411. Name string
  412. }
  413. // NetworkCreateResponse is the response message sent by the server for network create call
  414. type NetworkCreateResponse struct {
  415. ID string `json:"Id"`
  416. Warning string
  417. }
  418. // NetworkConnect represents the data to be used to connect a container to the network
  419. type NetworkConnect struct {
  420. Container string
  421. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  422. }
  423. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  424. type NetworkDisconnect struct {
  425. Container string
  426. Force bool
  427. }
  428. // NetworkInspectOptions holds parameters to inspect network
  429. type NetworkInspectOptions struct {
  430. Scope string
  431. Verbose bool
  432. }
  433. // Checkpoint represents the details of a checkpoint
  434. type Checkpoint struct {
  435. Name string // Name is the name of the checkpoint
  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 []*ImageSummary
  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 []ImageDeleteResponseItem
  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. }