types.go 20 KB

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