types.go 18 KB

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