types.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. package types // import "github.com/docker/docker/api/types"
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  6. "os"
  7. "strings"
  8. "time"
  9. "github.com/docker/docker/api/types/container"
  10. "github.com/docker/docker/api/types/filters"
  11. "github.com/docker/docker/api/types/mount"
  12. "github.com/docker/docker/api/types/network"
  13. "github.com/docker/docker/api/types/registry"
  14. "github.com/docker/docker/api/types/swarm"
  15. "github.com/docker/go-connections/nat"
  16. )
  17. // RootFS returns Image's RootFS description including the layer IDs.
  18. type RootFS struct {
  19. Type string
  20. Layers []string `json:",omitempty"`
  21. BaseLayer string `json:",omitempty"`
  22. }
  23. // ImageInspect contains response of Engine API:
  24. // GET "/images/{name:.*}/json"
  25. type ImageInspect struct {
  26. ID string `json:"Id"`
  27. RepoTags []string
  28. RepoDigests []string
  29. Parent string
  30. Comment string
  31. Created string
  32. Container string
  33. ContainerConfig *container.Config
  34. DockerVersion string
  35. Author string
  36. Config *container.Config
  37. Architecture string
  38. Variant string `json:",omitempty"`
  39. Os string
  40. OsVersion string `json:",omitempty"`
  41. Size int64
  42. VirtualSize int64
  43. GraphDriver GraphDriverData
  44. RootFS RootFS
  45. Metadata ImageMetadata
  46. }
  47. // ImageMetadata contains engine-local data about the image
  48. type ImageMetadata struct {
  49. LastTagTime time.Time `json:",omitempty"`
  50. }
  51. // Container contains response of Engine API:
  52. // GET "/containers/json"
  53. type Container struct {
  54. ID string `json:"Id"`
  55. Names []string
  56. Image string
  57. ImageID string
  58. Command string
  59. Created int64
  60. Ports []Port
  61. SizeRw int64 `json:",omitempty"`
  62. SizeRootFs int64 `json:",omitempty"`
  63. Labels map[string]string
  64. State string
  65. Status string
  66. HostConfig struct {
  67. NetworkMode string `json:",omitempty"`
  68. }
  69. NetworkSettings *SummaryNetworkSettings
  70. Mounts []MountPoint
  71. }
  72. // CopyConfig contains request body of Engine API:
  73. // POST "/containers/"+containerID+"/copy"
  74. type CopyConfig struct {
  75. Resource string
  76. }
  77. // ContainerPathStat is used to encode the header from
  78. // GET "/containers/{name:.*}/archive"
  79. // "Name" is the file or directory name.
  80. type ContainerPathStat struct {
  81. Name string `json:"name"`
  82. Size int64 `json:"size"`
  83. Mode os.FileMode `json:"mode"`
  84. Mtime time.Time `json:"mtime"`
  85. LinkTarget string `json:"linkTarget"`
  86. }
  87. // ContainerStats contains response of Engine API:
  88. // GET "/stats"
  89. type ContainerStats struct {
  90. Body io.ReadCloser `json:"body"`
  91. OSType string `json:"ostype"`
  92. }
  93. // Ping contains response of Engine API:
  94. // GET "/_ping"
  95. type Ping struct {
  96. APIVersion string
  97. OSType string
  98. Experimental bool
  99. BuilderVersion BuilderVersion
  100. }
  101. // ComponentVersion describes the version information for a specific component.
  102. type ComponentVersion struct {
  103. Name string
  104. Version string
  105. Details map[string]string `json:",omitempty"`
  106. }
  107. // Version contains response of Engine API:
  108. // GET "/version"
  109. type Version struct {
  110. Platform struct{ Name string } `json:",omitempty"`
  111. Components []ComponentVersion `json:",omitempty"`
  112. // The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility
  113. Version string
  114. APIVersion string `json:"ApiVersion"`
  115. MinAPIVersion string `json:"MinAPIVersion,omitempty"`
  116. GitCommit string
  117. GoVersion string
  118. Os string
  119. Arch string
  120. KernelVersion string `json:",omitempty"`
  121. Experimental bool `json:",omitempty"`
  122. BuildTime string `json:",omitempty"`
  123. }
  124. // Commit holds the Git-commit (SHA1) that a binary was built from, as reported
  125. // in the version-string of external tools, such as containerd, or runC.
  126. type Commit struct {
  127. ID string // ID is the actual commit ID of external tool.
  128. Expected string // Expected is the commit ID of external tool expected by dockerd as set at build time.
  129. }
  130. // Info contains response of Engine API:
  131. // GET "/info"
  132. type Info struct {
  133. ID string
  134. Containers int
  135. ContainersRunning int
  136. ContainersPaused int
  137. ContainersStopped int
  138. Images int
  139. Driver string
  140. DriverStatus [][2]string
  141. SystemStatus [][2]string `json:",omitempty"` // SystemStatus is only propagated by the Swarm standalone API
  142. Plugins PluginsInfo
  143. MemoryLimit bool
  144. SwapLimit bool
  145. KernelMemory bool
  146. KernelMemoryTCP bool
  147. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  148. CPUCfsQuota bool `json:"CpuCfsQuota"`
  149. CPUShares bool
  150. CPUSet bool
  151. PidsLimit bool
  152. IPv4Forwarding bool
  153. BridgeNfIptables bool
  154. BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
  155. Debug bool
  156. NFd int
  157. OomKillDisable bool
  158. NGoroutines int
  159. SystemTime string
  160. LoggingDriver string
  161. CgroupDriver string
  162. CgroupVersion string `json:",omitempty"`
  163. NEventsListener int
  164. KernelVersion string
  165. OperatingSystem string
  166. OSVersion string
  167. OSType string
  168. Architecture string
  169. IndexServerAddress string
  170. RegistryConfig *registry.ServiceConfig
  171. NCPU int
  172. MemTotal int64
  173. GenericResources []swarm.GenericResource
  174. DockerRootDir string
  175. HTTPProxy string `json:"HttpProxy"`
  176. HTTPSProxy string `json:"HttpsProxy"`
  177. NoProxy string
  178. Name string
  179. Labels []string
  180. ExperimentalBuild bool
  181. ServerVersion string
  182. ClusterStore string `json:",omitempty"` // Deprecated: host-discovery and overlay networks with external k/v stores are deprecated
  183. ClusterAdvertise string `json:",omitempty"` // Deprecated: host-discovery and overlay networks with external k/v stores are deprecated
  184. Runtimes map[string]Runtime
  185. DefaultRuntime string
  186. Swarm swarm.Info
  187. // LiveRestoreEnabled determines whether containers should be kept
  188. // running when the daemon is shutdown or upon daemon start if
  189. // running containers are detected
  190. LiveRestoreEnabled bool
  191. Isolation container.Isolation
  192. InitBinary string
  193. ContainerdCommit Commit
  194. RuncCommit Commit
  195. InitCommit Commit
  196. SecurityOptions []string
  197. ProductLicense string `json:",omitempty"`
  198. DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
  199. Warnings []string
  200. }
  201. // KeyValue holds a key/value pair
  202. type KeyValue struct {
  203. Key, Value string
  204. }
  205. // NetworkAddressPool is a temp struct used by Info struct
  206. type NetworkAddressPool struct {
  207. Base string
  208. Size int
  209. }
  210. // SecurityOpt contains the name and options of a security option
  211. type SecurityOpt struct {
  212. Name string
  213. Options []KeyValue
  214. }
  215. // DecodeSecurityOptions decodes a security options string slice to a type safe
  216. // SecurityOpt
  217. func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
  218. so := []SecurityOpt{}
  219. for _, opt := range opts {
  220. // support output from a < 1.13 docker daemon
  221. if !strings.Contains(opt, "=") {
  222. so = append(so, SecurityOpt{Name: opt})
  223. continue
  224. }
  225. secopt := SecurityOpt{}
  226. split := strings.Split(opt, ",")
  227. for _, s := range split {
  228. kv := strings.SplitN(s, "=", 2)
  229. if len(kv) != 2 {
  230. return nil, fmt.Errorf("invalid security option %q", s)
  231. }
  232. if kv[0] == "" || kv[1] == "" {
  233. return nil, errors.New("invalid empty security option")
  234. }
  235. if kv[0] == "name" {
  236. secopt.Name = kv[1]
  237. continue
  238. }
  239. secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]})
  240. }
  241. so = append(so, secopt)
  242. }
  243. return so, nil
  244. }
  245. // PluginsInfo is a temp struct holding Plugins name
  246. // registered with docker daemon. It is used by Info struct
  247. type PluginsInfo struct {
  248. // List of Volume plugins registered
  249. Volume []string
  250. // List of Network plugins registered
  251. Network []string
  252. // List of Authorization plugins registered
  253. Authorization []string
  254. // List of Log plugins registered
  255. Log []string
  256. }
  257. // ExecStartCheck is a temp struct used by execStart
  258. // Config fields is part of ExecConfig in runconfig package
  259. type ExecStartCheck struct {
  260. // ExecStart will first check if it's detached
  261. Detach bool
  262. // Check if there's a tty
  263. Tty bool
  264. }
  265. // HealthcheckResult stores information about a single run of a healthcheck probe
  266. type HealthcheckResult struct {
  267. Start time.Time // Start is the time this check started
  268. End time.Time // End is the time this check ended
  269. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  270. Output string // Output from last check
  271. }
  272. // Health states
  273. const (
  274. NoHealthcheck = "none" // Indicates there is no healthcheck
  275. Starting = "starting" // Starting indicates that the container is not yet ready
  276. Healthy = "healthy" // Healthy indicates that the container is running correctly
  277. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  278. )
  279. // Health stores information about the container's healthcheck results
  280. type Health struct {
  281. Status string // Status is one of Starting, Healthy or Unhealthy
  282. FailingStreak int // FailingStreak is the number of consecutive failures
  283. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  284. }
  285. // ContainerState stores container's running state
  286. // it's part of ContainerJSONBase and will return by "inspect" command
  287. type ContainerState struct {
  288. Status string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
  289. Running bool
  290. Paused bool
  291. Restarting bool
  292. OOMKilled bool
  293. Dead bool
  294. Pid int
  295. ExitCode int
  296. Error string
  297. StartedAt string
  298. FinishedAt string
  299. Health *Health `json:",omitempty"`
  300. }
  301. // ContainerNode stores information about the node that a container
  302. // is running on. It's only used by the Docker Swarm standalone API
  303. type ContainerNode struct {
  304. ID string
  305. IPAddress string `json:"IP"`
  306. Addr string
  307. Name string
  308. Cpus int
  309. Memory int64
  310. Labels map[string]string
  311. }
  312. // ContainerJSONBase contains response of Engine API:
  313. // GET "/containers/{name:.*}/json"
  314. type ContainerJSONBase struct {
  315. ID string `json:"Id"`
  316. Created string
  317. Path string
  318. Args []string
  319. State *ContainerState
  320. Image string
  321. ResolvConfPath string
  322. HostnamePath string
  323. HostsPath string
  324. LogPath string
  325. Node *ContainerNode `json:",omitempty"` // Node is only propagated by Docker Swarm standalone API
  326. Name string
  327. RestartCount int
  328. Driver string
  329. Platform string
  330. MountLabel string
  331. ProcessLabel string
  332. AppArmorProfile string
  333. ExecIDs []string
  334. HostConfig *container.HostConfig
  335. GraphDriver GraphDriverData
  336. SizeRw *int64 `json:",omitempty"`
  337. SizeRootFs *int64 `json:",omitempty"`
  338. }
  339. // ContainerJSON is newly used struct along with MountPoint
  340. type ContainerJSON struct {
  341. *ContainerJSONBase
  342. Mounts []MountPoint
  343. Config *container.Config
  344. NetworkSettings *NetworkSettings
  345. }
  346. // NetworkSettings exposes the network settings in the api
  347. type NetworkSettings struct {
  348. NetworkSettingsBase
  349. DefaultNetworkSettings
  350. Networks map[string]*network.EndpointSettings
  351. }
  352. // SummaryNetworkSettings provides a summary of container's networks
  353. // in /containers/json
  354. type SummaryNetworkSettings struct {
  355. Networks map[string]*network.EndpointSettings
  356. }
  357. // NetworkSettingsBase holds basic information about networks
  358. type NetworkSettingsBase struct {
  359. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  360. SandboxID string // SandboxID uniquely represents a container's network stack
  361. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  362. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  363. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  364. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  365. SandboxKey string // SandboxKey identifies the sandbox
  366. SecondaryIPAddresses []network.Address
  367. SecondaryIPv6Addresses []network.Address
  368. }
  369. // DefaultNetworkSettings holds network information
  370. // during the 2 release deprecation period.
  371. // It will be removed in Docker 1.11.
  372. type DefaultNetworkSettings struct {
  373. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  374. Gateway string // Gateway holds the gateway address for the network
  375. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  376. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  377. IPAddress string // IPAddress holds the IPv4 address for the network
  378. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  379. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  380. MacAddress string // MacAddress holds the MAC address for the network
  381. }
  382. // MountPoint represents a mount point configuration inside the container.
  383. // This is used for reporting the mountpoints in use by a container.
  384. type MountPoint struct {
  385. Type mount.Type `json:",omitempty"`
  386. Name string `json:",omitempty"`
  387. Source string
  388. Destination string
  389. Driver string `json:",omitempty"`
  390. Mode string
  391. RW bool
  392. Propagation mount.Propagation
  393. }
  394. // NetworkResource is the body of the "get network" http response message
  395. type NetworkResource struct {
  396. Name string // Name is the requested name of the network
  397. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  398. Created time.Time // Created is the time the network created
  399. Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
  400. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  401. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  402. IPAM network.IPAM // IPAM is the network's IP Address Management
  403. Internal bool // Internal represents if the network is used internal only
  404. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  405. Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
  406. ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
  407. 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.
  408. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  409. Options map[string]string // Options holds the network specific options to use for when creating the network
  410. Labels map[string]string // Labels holds metadata specific to the network being created
  411. Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
  412. Services map[string]network.ServiceInfo `json:",omitempty"`
  413. }
  414. // EndpointResource contains network resources allocated and used for a container in a network
  415. type EndpointResource struct {
  416. Name string
  417. EndpointID string
  418. MacAddress string
  419. IPv4Address string
  420. IPv6Address string
  421. }
  422. // NetworkCreate is the expected body of the "create network" http request message
  423. type NetworkCreate struct {
  424. // Check for networks with duplicate names.
  425. // Network is primarily keyed based on a random ID and not on the name.
  426. // Network name is strictly a user-friendly alias to the network
  427. // which is uniquely identified using ID.
  428. // And there is no guaranteed way to check for duplicates.
  429. // Option CheckDuplicate is there to provide a best effort checking of any networks
  430. // which has the same name but it is not guaranteed to catch all name collisions.
  431. CheckDuplicate bool
  432. Driver string
  433. Scope string
  434. EnableIPv6 bool
  435. IPAM *network.IPAM
  436. Internal bool
  437. Attachable bool
  438. Ingress bool
  439. ConfigOnly bool
  440. ConfigFrom *network.ConfigReference
  441. Options map[string]string
  442. Labels map[string]string
  443. }
  444. // NetworkCreateRequest is the request message sent to the server for network create call.
  445. type NetworkCreateRequest struct {
  446. NetworkCreate
  447. Name string
  448. }
  449. // NetworkCreateResponse is the response message sent by the server for network create call
  450. type NetworkCreateResponse struct {
  451. ID string `json:"Id"`
  452. Warning string
  453. }
  454. // NetworkConnect represents the data to be used to connect a container to the network
  455. type NetworkConnect struct {
  456. Container string
  457. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  458. }
  459. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  460. type NetworkDisconnect struct {
  461. Container string
  462. Force bool
  463. }
  464. // NetworkInspectOptions holds parameters to inspect network
  465. type NetworkInspectOptions struct {
  466. Scope string
  467. Verbose bool
  468. }
  469. // Checkpoint represents the details of a checkpoint
  470. type Checkpoint struct {
  471. Name string // Name is the name of the checkpoint
  472. }
  473. // Runtime describes an OCI runtime
  474. type Runtime struct {
  475. Path string `json:"path"`
  476. Args []string `json:"runtimeArgs,omitempty"`
  477. // This is exposed here only for internal use
  478. // It is not currently supported to specify custom shim configs
  479. Shim *ShimConfig `json:"-"`
  480. }
  481. // ShimConfig is used by runtime to configure containerd shims
  482. type ShimConfig struct {
  483. Binary string
  484. Opts interface{}
  485. }
  486. // DiskUsage contains response of Engine API:
  487. // GET "/system/df"
  488. type DiskUsage struct {
  489. LayersSize int64
  490. Images []*ImageSummary
  491. Containers []*Container
  492. Volumes []*Volume
  493. BuildCache []*BuildCache
  494. BuilderSize int64 // deprecated
  495. }
  496. // ContainersPruneReport contains the response for Engine API:
  497. // POST "/containers/prune"
  498. type ContainersPruneReport struct {
  499. ContainersDeleted []string
  500. SpaceReclaimed uint64
  501. }
  502. // VolumesPruneReport contains the response for Engine API:
  503. // POST "/volumes/prune"
  504. type VolumesPruneReport struct {
  505. VolumesDeleted []string
  506. SpaceReclaimed uint64
  507. }
  508. // ImagesPruneReport contains the response for Engine API:
  509. // POST "/images/prune"
  510. type ImagesPruneReport struct {
  511. ImagesDeleted []ImageDeleteResponseItem
  512. SpaceReclaimed uint64
  513. }
  514. // BuildCachePruneReport contains the response for Engine API:
  515. // POST "/build/prune"
  516. type BuildCachePruneReport struct {
  517. CachesDeleted []string
  518. SpaceReclaimed uint64
  519. }
  520. // NetworksPruneReport contains the response for Engine API:
  521. // POST "/networks/prune"
  522. type NetworksPruneReport struct {
  523. NetworksDeleted []string
  524. }
  525. // SecretCreateResponse contains the information returned to a client
  526. // on the creation of a new secret.
  527. type SecretCreateResponse struct {
  528. // ID is the id of the created secret.
  529. ID string
  530. }
  531. // SecretListOptions holds parameters to list secrets
  532. type SecretListOptions struct {
  533. Filters filters.Args
  534. }
  535. // ConfigCreateResponse contains the information returned to a client
  536. // on the creation of a new config.
  537. type ConfigCreateResponse struct {
  538. // ID is the id of the created config.
  539. ID string
  540. }
  541. // ConfigListOptions holds parameters to list configs
  542. type ConfigListOptions struct {
  543. Filters filters.Args
  544. }
  545. // PushResult contains the tag, manifest digest, and manifest size from the
  546. // push. It's used to signal this information to the trust code in the client
  547. // so it can sign the manifest if necessary.
  548. type PushResult struct {
  549. Tag string
  550. Digest string
  551. Size int
  552. }
  553. // BuildResult contains the image id of a successful build
  554. type BuildResult struct {
  555. ID string
  556. }
  557. // BuildCache contains information about a build cache record
  558. type BuildCache struct {
  559. ID string
  560. Parent string
  561. Type string
  562. Description string
  563. InUse bool
  564. Shared bool
  565. Size int64
  566. CreatedAt time.Time
  567. LastUsedAt *time.Time
  568. UsageCount int
  569. }
  570. // BuildCachePruneOptions hold parameters to prune the build cache
  571. type BuildCachePruneOptions struct {
  572. All bool
  573. KeepStorage int64
  574. Filters filters.Args
  575. }