types.go 20 KB

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