types.go 20 KB

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