types.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. Warnings []string
  199. }
  200. // KeyValue holds a key/value pair
  201. type KeyValue struct {
  202. Key, Value string
  203. }
  204. // SecurityOpt contains the name and options of a security option
  205. type SecurityOpt struct {
  206. Name string
  207. Options []KeyValue
  208. }
  209. // DecodeSecurityOptions decodes a security options string slice to a type safe
  210. // SecurityOpt
  211. func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
  212. so := []SecurityOpt{}
  213. for _, opt := range opts {
  214. // support output from a < 1.13 docker daemon
  215. if !strings.Contains(opt, "=") {
  216. so = append(so, SecurityOpt{Name: opt})
  217. continue
  218. }
  219. secopt := SecurityOpt{}
  220. split := strings.Split(opt, ",")
  221. for _, s := range split {
  222. kv := strings.SplitN(s, "=", 2)
  223. if len(kv) != 2 {
  224. return nil, fmt.Errorf("invalid security option %q", s)
  225. }
  226. if kv[0] == "" || kv[1] == "" {
  227. return nil, errors.New("invalid empty security option")
  228. }
  229. if kv[0] == "name" {
  230. secopt.Name = kv[1]
  231. continue
  232. }
  233. secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]})
  234. }
  235. so = append(so, secopt)
  236. }
  237. return so, nil
  238. }
  239. // PluginsInfo is a temp struct holding Plugins name
  240. // registered with docker daemon. It is used by Info struct
  241. type PluginsInfo struct {
  242. // List of Volume plugins registered
  243. Volume []string
  244. // List of Network plugins registered
  245. Network []string
  246. // List of Authorization plugins registered
  247. Authorization []string
  248. // List of Log plugins registered
  249. Log []string
  250. }
  251. // ExecStartCheck is a temp struct used by execStart
  252. // Config fields is part of ExecConfig in runconfig package
  253. type ExecStartCheck struct {
  254. // ExecStart will first check if it's detached
  255. Detach bool
  256. // Check if there's a tty
  257. Tty bool
  258. }
  259. // HealthcheckResult stores information about a single run of a healthcheck probe
  260. type HealthcheckResult struct {
  261. Start time.Time // Start is the time this check started
  262. End time.Time // End is the time this check ended
  263. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  264. Output string // Output from last check
  265. }
  266. // Health states
  267. const (
  268. NoHealthcheck = "none" // Indicates there is no healthcheck
  269. Starting = "starting" // Starting indicates that the container is not yet ready
  270. Healthy = "healthy" // Healthy indicates that the container is running correctly
  271. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  272. )
  273. // Health stores information about the container's healthcheck results
  274. type Health struct {
  275. Status string // Status is one of Starting, Healthy or Unhealthy
  276. FailingStreak int // FailingStreak is the number of consecutive failures
  277. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  278. }
  279. // ContainerState stores container's running state
  280. // it's part of ContainerJSONBase and will return by "inspect" command
  281. type ContainerState struct {
  282. Status string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
  283. Running bool
  284. Paused bool
  285. Restarting bool
  286. OOMKilled bool
  287. Dead bool
  288. Pid int
  289. ExitCode int
  290. Error string
  291. StartedAt string
  292. FinishedAt string
  293. Health *Health `json:",omitempty"`
  294. }
  295. // ContainerNode stores information about the node that a container
  296. // is running on. It's only used by the Docker Swarm standalone API
  297. type ContainerNode struct {
  298. ID string
  299. IPAddress string `json:"IP"`
  300. Addr string
  301. Name string
  302. Cpus int
  303. Memory int64
  304. Labels map[string]string
  305. }
  306. // ContainerJSONBase contains response of Engine API:
  307. // GET "/containers/{name:.*}/json"
  308. type ContainerJSONBase struct {
  309. ID string `json:"Id"`
  310. Created string
  311. Path string
  312. Args []string
  313. State *ContainerState
  314. Image string
  315. ResolvConfPath string
  316. HostnamePath string
  317. HostsPath string
  318. LogPath string
  319. Node *ContainerNode `json:",omitempty"` // Node is only propagated by Docker Swarm standalone API
  320. Name string
  321. RestartCount int
  322. Driver string
  323. Platform string
  324. MountLabel string
  325. ProcessLabel string
  326. AppArmorProfile string
  327. ExecIDs []string
  328. HostConfig *container.HostConfig
  329. GraphDriver GraphDriverData
  330. SizeRw *int64 `json:",omitempty"`
  331. SizeRootFs *int64 `json:",omitempty"`
  332. }
  333. // ContainerJSON is newly used struct along with MountPoint
  334. type ContainerJSON struct {
  335. *ContainerJSONBase
  336. Mounts []MountPoint
  337. Config *container.Config
  338. NetworkSettings *NetworkSettings
  339. }
  340. // NetworkSettings exposes the network settings in the api
  341. type NetworkSettings struct {
  342. NetworkSettingsBase
  343. DefaultNetworkSettings
  344. Networks map[string]*network.EndpointSettings
  345. }
  346. // SummaryNetworkSettings provides a summary of container's networks
  347. // in /containers/json
  348. type SummaryNetworkSettings struct {
  349. Networks map[string]*network.EndpointSettings
  350. }
  351. // NetworkSettingsBase holds basic information about networks
  352. type NetworkSettingsBase struct {
  353. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  354. SandboxID string // SandboxID uniquely represents a container's network stack
  355. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  356. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  357. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  358. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  359. SandboxKey string // SandboxKey identifies the sandbox
  360. SecondaryIPAddresses []network.Address
  361. SecondaryIPv6Addresses []network.Address
  362. }
  363. // DefaultNetworkSettings holds network information
  364. // during the 2 release deprecation period.
  365. // It will be removed in Docker 1.11.
  366. type DefaultNetworkSettings struct {
  367. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  368. Gateway string // Gateway holds the gateway address for the network
  369. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  370. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  371. IPAddress string // IPAddress holds the IPv4 address for the network
  372. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  373. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  374. MacAddress string // MacAddress holds the MAC address for the network
  375. }
  376. // MountPoint represents a mount point configuration inside the container.
  377. // This is used for reporting the mountpoints in use by a container.
  378. type MountPoint struct {
  379. Type mount.Type `json:",omitempty"`
  380. Name string `json:",omitempty"`
  381. Source string
  382. Destination string
  383. Driver string `json:",omitempty"`
  384. Mode string
  385. RW bool
  386. Propagation mount.Propagation
  387. }
  388. // NetworkResource is the body of the "get network" http response message
  389. type NetworkResource struct {
  390. Name string // Name is the requested name of the network
  391. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  392. Created time.Time // Created is the time the network created
  393. Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
  394. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  395. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  396. IPAM network.IPAM // IPAM is the network's IP Address Management
  397. Internal bool // Internal represents if the network is used internal only
  398. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  399. Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
  400. ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
  401. 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.
  402. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  403. Options map[string]string // Options holds the network specific options to use for when creating the network
  404. Labels map[string]string // Labels holds metadata specific to the network being created
  405. Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
  406. Services map[string]network.ServiceInfo `json:",omitempty"`
  407. }
  408. // EndpointResource contains network resources allocated and used for a container in a network
  409. type EndpointResource struct {
  410. Name string
  411. EndpointID string
  412. MacAddress string
  413. IPv4Address string
  414. IPv6Address string
  415. }
  416. // NetworkCreate is the expected body of the "create network" http request message
  417. type NetworkCreate struct {
  418. // Check for networks with duplicate names.
  419. // Network is primarily keyed based on a random ID and not on the name.
  420. // Network name is strictly a user-friendly alias to the network
  421. // which is uniquely identified using ID.
  422. // And there is no guaranteed way to check for duplicates.
  423. // Option CheckDuplicate is there to provide a best effort checking of any networks
  424. // which has the same name but it is not guaranteed to catch all name collisions.
  425. CheckDuplicate bool
  426. Driver string
  427. Scope string
  428. EnableIPv6 bool
  429. IPAM *network.IPAM
  430. Internal bool
  431. Attachable bool
  432. Ingress bool
  433. ConfigOnly bool
  434. ConfigFrom *network.ConfigReference
  435. Options map[string]string
  436. Labels map[string]string
  437. }
  438. // NetworkCreateRequest is the request message sent to the server for network create call.
  439. type NetworkCreateRequest struct {
  440. NetworkCreate
  441. Name string
  442. }
  443. // NetworkCreateResponse is the response message sent by the server for network create call
  444. type NetworkCreateResponse struct {
  445. ID string `json:"Id"`
  446. Warning string
  447. }
  448. // NetworkConnect represents the data to be used to connect a container to the network
  449. type NetworkConnect struct {
  450. Container string
  451. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  452. }
  453. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  454. type NetworkDisconnect struct {
  455. Container string
  456. Force bool
  457. }
  458. // NetworkInspectOptions holds parameters to inspect network
  459. type NetworkInspectOptions struct {
  460. Scope string
  461. Verbose bool
  462. }
  463. // Checkpoint represents the details of a checkpoint
  464. type Checkpoint struct {
  465. Name string // Name is the name of the checkpoint
  466. }
  467. // Runtime describes an OCI runtime
  468. type Runtime struct {
  469. Path string `json:"path"`
  470. Args []string `json:"runtimeArgs,omitempty"`
  471. // This is exposed here only for internal use
  472. // It is not currently supported to specify custom shim configs
  473. Shim *ShimConfig `json:"-"`
  474. }
  475. // ShimConfig is used by runtime to configure containerd shims
  476. type ShimConfig struct {
  477. Binary string
  478. Opts interface{}
  479. }
  480. // DiskUsage contains response of Engine API:
  481. // GET "/system/df"
  482. type DiskUsage struct {
  483. LayersSize int64
  484. Images []*ImageSummary
  485. Containers []*Container
  486. Volumes []*Volume
  487. BuildCache []*BuildCache
  488. BuilderSize int64 // deprecated
  489. }
  490. // ContainersPruneReport contains the response for Engine API:
  491. // POST "/containers/prune"
  492. type ContainersPruneReport struct {
  493. ContainersDeleted []string
  494. SpaceReclaimed uint64
  495. }
  496. // VolumesPruneReport contains the response for Engine API:
  497. // POST "/volumes/prune"
  498. type VolumesPruneReport struct {
  499. VolumesDeleted []string
  500. SpaceReclaimed uint64
  501. }
  502. // ImagesPruneReport contains the response for Engine API:
  503. // POST "/images/prune"
  504. type ImagesPruneReport struct {
  505. ImagesDeleted []ImageDeleteResponseItem
  506. SpaceReclaimed uint64
  507. }
  508. // BuildCachePruneReport contains the response for Engine API:
  509. // POST "/build/prune"
  510. type BuildCachePruneReport struct {
  511. CachesDeleted []string
  512. SpaceReclaimed uint64
  513. }
  514. // NetworksPruneReport contains the response for Engine API:
  515. // POST "/networks/prune"
  516. type NetworksPruneReport struct {
  517. NetworksDeleted []string
  518. }
  519. // SecretCreateResponse contains the information returned to a client
  520. // on the creation of a new secret.
  521. type SecretCreateResponse struct {
  522. // ID is the id of the created secret.
  523. ID string
  524. }
  525. // SecretListOptions holds parameters to list secrets
  526. type SecretListOptions struct {
  527. Filters filters.Args
  528. }
  529. // ConfigCreateResponse contains the information returned to a client
  530. // on the creation of a new config.
  531. type ConfigCreateResponse struct {
  532. // ID is the id of the created config.
  533. ID string
  534. }
  535. // ConfigListOptions holds parameters to list configs
  536. type ConfigListOptions struct {
  537. Filters filters.Args
  538. }
  539. // PushResult contains the tag, manifest digest, and manifest size from the
  540. // push. It's used to signal this information to the trust code in the client
  541. // so it can sign the manifest if necessary.
  542. type PushResult struct {
  543. Tag string
  544. Digest string
  545. Size int
  546. }
  547. // BuildResult contains the image id of a successful build
  548. type BuildResult struct {
  549. ID string
  550. }
  551. // BuildCache contains information about a build cache record
  552. type BuildCache struct {
  553. ID string
  554. Parent string
  555. Type string
  556. Description string
  557. InUse bool
  558. Shared bool
  559. Size int64
  560. CreatedAt time.Time
  561. LastUsedAt *time.Time
  562. UsageCount int
  563. }
  564. // BuildCachePruneOptions hold parameters to prune the build cache
  565. type BuildCachePruneOptions struct {
  566. All bool
  567. KeepStorage int64
  568. Filters filters.Args
  569. }