types.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. package types
  2. import (
  3. "io"
  4. "os"
  5. "time"
  6. "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/api/types/mount"
  8. "github.com/docker/docker/api/types/network"
  9. "github.com/docker/docker/api/types/registry"
  10. "github.com/docker/docker/api/types/swarm"
  11. "github.com/docker/go-connections/nat"
  12. )
  13. // ContainerChange contains response of Remote API:
  14. // GET "/containers/{name:.*}/changes"
  15. type ContainerChange struct {
  16. Kind int
  17. Path string
  18. }
  19. // ImageHistory contains response of Remote API:
  20. // GET "/images/{name:.*}/history"
  21. type ImageHistory struct {
  22. ID string `json:"Id"`
  23. Created int64
  24. CreatedBy string
  25. Tags []string
  26. Size int64
  27. Comment string
  28. }
  29. // ImageDelete contains response of Remote API:
  30. // DELETE "/images/{name:.*}"
  31. type ImageDelete struct {
  32. Untagged string `json:",omitempty"`
  33. Deleted string `json:",omitempty"`
  34. }
  35. // GraphDriverData returns Image's graph driver config info
  36. // when calling inspect command
  37. type GraphDriverData struct {
  38. Name string
  39. Data map[string]string
  40. }
  41. // RootFS returns Image's RootFS description including the layer IDs.
  42. type RootFS struct {
  43. Type string
  44. Layers []string `json:",omitempty"`
  45. BaseLayer string `json:",omitempty"`
  46. }
  47. // ImageInspect contains response of Remote API:
  48. // GET "/images/{name:.*}/json"
  49. type ImageInspect struct {
  50. ID string `json:"Id"`
  51. RepoTags []string
  52. RepoDigests []string
  53. Parent string
  54. Comment string
  55. Created string
  56. Container string
  57. ContainerConfig *container.Config
  58. DockerVersion string
  59. Author string
  60. Config *container.Config
  61. Architecture string
  62. Os string
  63. OsVersion string `json:",omitempty"`
  64. Size int64
  65. VirtualSize int64
  66. GraphDriver GraphDriverData
  67. RootFS RootFS
  68. }
  69. // Container contains response of Remote API:
  70. // GET "/containers/json"
  71. type Container struct {
  72. ID string `json:"Id"`
  73. Names []string
  74. Image string
  75. ImageID string
  76. Command string
  77. Created int64
  78. Ports []Port
  79. SizeRw int64 `json:",omitempty"`
  80. SizeRootFs int64 `json:",omitempty"`
  81. Labels map[string]string
  82. State string
  83. Status string
  84. HostConfig struct {
  85. NetworkMode string `json:",omitempty"`
  86. }
  87. NetworkSettings *SummaryNetworkSettings
  88. Mounts []MountPoint
  89. }
  90. // CopyConfig contains request body of Remote API:
  91. // POST "/containers/"+containerID+"/copy"
  92. type CopyConfig struct {
  93. Resource string
  94. }
  95. // ContainerPathStat is used to encode the header from
  96. // GET "/containers/{name:.*}/archive"
  97. // "Name" is the file or directory name.
  98. type ContainerPathStat struct {
  99. Name string `json:"name"`
  100. Size int64 `json:"size"`
  101. Mode os.FileMode `json:"mode"`
  102. Mtime time.Time `json:"mtime"`
  103. LinkTarget string `json:"linkTarget"`
  104. }
  105. // ContainerStats contains response of Remote API:
  106. // GET "/stats"
  107. type ContainerStats struct {
  108. Body io.ReadCloser `json:"body"`
  109. OSType string `json:"ostype"`
  110. }
  111. // ContainerProcessList contains response of Remote API:
  112. // GET "/containers/{name:.*}/top"
  113. type ContainerProcessList struct {
  114. Processes [][]string
  115. Titles []string
  116. }
  117. // Version contains response of Remote API:
  118. // GET "/version"
  119. type Version struct {
  120. Version string
  121. APIVersion string `json:"ApiVersion"`
  122. MinAPIVersion string `json:"MinAPIVersion,omitempty"`
  123. GitCommit string
  124. GoVersion string
  125. Os string
  126. Arch string
  127. KernelVersion string `json:",omitempty"`
  128. Experimental bool `json:",omitempty"`
  129. BuildTime string `json:",omitempty"`
  130. }
  131. // Info contains response of Remote API:
  132. // GET "/info"
  133. type Info struct {
  134. ID string
  135. Containers int
  136. ContainersRunning int
  137. ContainersPaused int
  138. ContainersStopped int
  139. Images int
  140. Driver string
  141. DriverStatus [][2]string
  142. SystemStatus [][2]string
  143. Plugins PluginsInfo
  144. MemoryLimit bool
  145. SwapLimit bool
  146. KernelMemory bool
  147. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  148. CPUCfsQuota bool `json:"CpuCfsQuota"`
  149. CPUShares bool
  150. CPUSet 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. 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. SecurityOptions []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. }
  190. // PluginsInfo is a temp struct holding Plugins name
  191. // registered with docker daemon. It is used by Info struct
  192. type PluginsInfo struct {
  193. // List of Volume plugins registered
  194. Volume []string
  195. // List of Network plugins registered
  196. Network []string
  197. // List of Authorization plugins registered
  198. Authorization []string
  199. }
  200. // ExecStartCheck is a temp struct used by execStart
  201. // Config fields is part of ExecConfig in runconfig package
  202. type ExecStartCheck struct {
  203. // ExecStart will first check if it's detached
  204. Detach bool
  205. // Check if there's a tty
  206. Tty bool
  207. }
  208. // HealthcheckResult stores information about a single run of a healthcheck probe
  209. type HealthcheckResult struct {
  210. Start time.Time // Start is the time this check started
  211. End time.Time // End is the time this check ended
  212. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  213. Output string // Output from last check
  214. }
  215. // Health states
  216. const (
  217. NoHealthcheck = "none" // Indicates there is no healthcheck
  218. Starting = "starting" // Starting indicates that the container is not yet ready
  219. Healthy = "healthy" // Healthy indicates that the container is running correctly
  220. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  221. )
  222. // Health stores information about the container's healthcheck results
  223. type Health struct {
  224. Status string // Status is one of Starting, Healthy or Unhealthy
  225. FailingStreak int // FailingStreak is the number of consecutive failures
  226. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  227. }
  228. // ContainerState stores container's running state
  229. // it's part of ContainerJSONBase and will return by "inspect" command
  230. type ContainerState struct {
  231. Status string
  232. Running bool
  233. Paused bool
  234. Restarting bool
  235. OOMKilled bool
  236. Dead bool
  237. Pid int
  238. ExitCode int
  239. Error string
  240. StartedAt string
  241. FinishedAt string
  242. Health *Health `json:",omitempty"`
  243. }
  244. // ContainerNode stores information about the node that a container
  245. // is running on. It's only available in Docker Swarm
  246. type ContainerNode struct {
  247. ID string
  248. IPAddress string `json:"IP"`
  249. Addr string
  250. Name string
  251. Cpus int
  252. Memory int64
  253. Labels map[string]string
  254. }
  255. // ContainerJSONBase contains response of Remote API:
  256. // GET "/containers/{name:.*}/json"
  257. type ContainerJSONBase struct {
  258. ID string `json:"Id"`
  259. Created string
  260. Path string
  261. Args []string
  262. State *ContainerState
  263. Image string
  264. ResolvConfPath string
  265. HostnamePath string
  266. HostsPath string
  267. LogPath string
  268. Node *ContainerNode `json:",omitempty"`
  269. Name string
  270. RestartCount int
  271. Driver string
  272. MountLabel string
  273. ProcessLabel string
  274. AppArmorProfile string
  275. ExecIDs []string
  276. HostConfig *container.HostConfig
  277. GraphDriver GraphDriverData
  278. SizeRw *int64 `json:",omitempty"`
  279. SizeRootFs *int64 `json:",omitempty"`
  280. }
  281. // ContainerJSON is newly used struct along with MountPoint
  282. type ContainerJSON struct {
  283. *ContainerJSONBase
  284. Mounts []MountPoint
  285. Config *container.Config
  286. NetworkSettings *NetworkSettings
  287. }
  288. // NetworkSettings exposes the network settings in the api
  289. type NetworkSettings struct {
  290. NetworkSettingsBase
  291. DefaultNetworkSettings
  292. Networks map[string]*network.EndpointSettings
  293. }
  294. // SummaryNetworkSettings provides a summary of container's networks
  295. // in /containers/json
  296. type SummaryNetworkSettings struct {
  297. Networks map[string]*network.EndpointSettings
  298. }
  299. // NetworkSettingsBase holds basic information about networks
  300. type NetworkSettingsBase struct {
  301. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  302. SandboxID string // SandboxID uniquely represents a container's network stack
  303. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  304. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  305. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  306. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  307. SandboxKey string // SandboxKey identifies the sandbox
  308. SecondaryIPAddresses []network.Address
  309. SecondaryIPv6Addresses []network.Address
  310. }
  311. // DefaultNetworkSettings holds network information
  312. // during the 2 release deprecation period.
  313. // It will be removed in Docker 1.11.
  314. type DefaultNetworkSettings struct {
  315. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  316. Gateway string // Gateway holds the gateway address for the network
  317. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  318. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  319. IPAddress string // IPAddress holds the IPv4 address for the network
  320. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  321. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  322. MacAddress string // MacAddress holds the MAC address for the network
  323. }
  324. // MountPoint represents a mount point configuration inside the container.
  325. // This is used for reporting the mountpoints in use by a container.
  326. type MountPoint struct {
  327. Type mount.Type `json:",omitempty"`
  328. Name string `json:",omitempty"`
  329. Source string
  330. Destination string
  331. Driver string `json:",omitempty"`
  332. Mode string
  333. RW bool
  334. Propagation mount.Propagation
  335. }
  336. // NetworkResource is the body of the "get network" http response message
  337. type NetworkResource struct {
  338. Name string // Name is the requested name of the network
  339. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  340. Created time.Time // Created is the time the network created
  341. Scope string // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
  342. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  343. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  344. IPAM network.IPAM // IPAM is the network's IP Address Management
  345. Internal bool // Internal represents if the network is used internal only
  346. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  347. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  348. Options map[string]string // Options holds the network specific options to use for when creating the network
  349. Labels map[string]string // Labels holds metadata specific to the network being created
  350. }
  351. // EndpointResource contains network resources allocated and used for a container in a network
  352. type EndpointResource struct {
  353. Name string
  354. EndpointID string
  355. MacAddress string
  356. IPv4Address string
  357. IPv6Address string
  358. }
  359. // NetworkCreate is the expected body of the "create network" http request message
  360. type NetworkCreate struct {
  361. CheckDuplicate bool
  362. Driver string
  363. EnableIPv6 bool
  364. IPAM *network.IPAM
  365. Internal bool
  366. Attachable bool
  367. Options map[string]string
  368. Labels map[string]string
  369. }
  370. // NetworkCreateRequest is the request message sent to the server for network create call.
  371. type NetworkCreateRequest struct {
  372. NetworkCreate
  373. Name string
  374. }
  375. // NetworkCreateResponse is the response message sent by the server for network create call
  376. type NetworkCreateResponse struct {
  377. ID string `json:"Id"`
  378. Warning string
  379. }
  380. // NetworkConnect represents the data to be used to connect a container to the network
  381. type NetworkConnect struct {
  382. Container string
  383. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  384. }
  385. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  386. type NetworkDisconnect struct {
  387. Container string
  388. Force bool
  389. }
  390. // Checkpoint represents the details of a checkpoint
  391. type Checkpoint struct {
  392. Name string // Name is the name of the checkpoint
  393. }
  394. // Runtime describes an OCI runtime
  395. type Runtime struct {
  396. Path string `json:"path"`
  397. Args []string `json:"runtimeArgs,omitempty"`
  398. }
  399. // DiskUsage contains response of Remote API:
  400. // GET "/system/df"
  401. type DiskUsage struct {
  402. LayersSize int64
  403. Images []*ImageSummary
  404. Containers []*Container
  405. Volumes []*Volume
  406. }
  407. // ImagesPruneConfig contains the configuration for Remote API:
  408. // POST "/images/prune"
  409. type ImagesPruneConfig struct {
  410. DanglingOnly bool
  411. }
  412. // ContainersPruneConfig contains the configuration for Remote API:
  413. // POST "/images/prune"
  414. type ContainersPruneConfig struct {
  415. }
  416. // VolumesPruneConfig contains the configuration for Remote API:
  417. // POST "/images/prune"
  418. type VolumesPruneConfig struct {
  419. }
  420. // NetworksPruneConfig contains the configuration for Remote API:
  421. // POST "/networks/prune"
  422. type NetworksPruneConfig struct {
  423. }
  424. // ContainersPruneReport contains the response for Remote API:
  425. // POST "/containers/prune"
  426. type ContainersPruneReport struct {
  427. ContainersDeleted []string
  428. SpaceReclaimed uint64
  429. }
  430. // VolumesPruneReport contains the response for Remote API:
  431. // POST "/volumes/prune"
  432. type VolumesPruneReport struct {
  433. VolumesDeleted []string
  434. SpaceReclaimed uint64
  435. }
  436. // ImagesPruneReport contains the response for Remote API:
  437. // POST "/images/prune"
  438. type ImagesPruneReport struct {
  439. ImagesDeleted []ImageDelete
  440. SpaceReclaimed uint64
  441. }
  442. // NetworksPruneReport contains the response for Remote API:
  443. // POST "/networks/prune"
  444. type NetworksPruneReport struct {
  445. NetworksDeleted []string
  446. }