types.go 19 KB

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