types.go 20 KB

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