types.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. // Info contains response of Remote API:
  118. // GET "/_ping"
  119. type Ping struct {
  120. APIVersion string
  121. Experimental bool
  122. }
  123. // Version contains response of Remote API:
  124. // GET "/version"
  125. type Version struct {
  126. Version string
  127. APIVersion string `json:"ApiVersion"`
  128. MinAPIVersion string `json:"MinAPIVersion,omitempty"`
  129. GitCommit string
  130. GoVersion string
  131. Os string
  132. Arch string
  133. KernelVersion string `json:",omitempty"`
  134. Experimental bool `json:",omitempty"`
  135. BuildTime string `json:",omitempty"`
  136. }
  137. // InfoBase contains the base response of Remote API:
  138. // GET "/info"
  139. type InfoBase struct {
  140. ID string
  141. Containers int
  142. ContainersRunning int
  143. ContainersPaused int
  144. ContainersStopped int
  145. Images int
  146. Driver string
  147. DriverStatus [][2]string
  148. SystemStatus [][2]string
  149. Plugins PluginsInfo
  150. MemoryLimit bool
  151. SwapLimit bool
  152. KernelMemory bool
  153. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  154. CPUCfsQuota bool `json:"CpuCfsQuota"`
  155. CPUShares bool
  156. CPUSet bool
  157. IPv4Forwarding bool
  158. BridgeNfIptables bool
  159. BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
  160. Debug bool
  161. NFd int
  162. OomKillDisable bool
  163. NGoroutines int
  164. SystemTime string
  165. LoggingDriver string
  166. CgroupDriver string
  167. NEventsListener int
  168. KernelVersion string
  169. OperatingSystem string
  170. OSType string
  171. Architecture string
  172. IndexServerAddress string
  173. RegistryConfig *registry.ServiceConfig
  174. NCPU int
  175. MemTotal int64
  176. DockerRootDir string
  177. HTTPProxy string `json:"HttpProxy"`
  178. HTTPSProxy string `json:"HttpsProxy"`
  179. NoProxy string
  180. Name string
  181. Labels []string
  182. ExperimentalBuild bool
  183. ServerVersion string
  184. ClusterStore string
  185. ClusterAdvertise string
  186. Runtimes map[string]Runtime
  187. DefaultRuntime string
  188. Swarm swarm.Info
  189. // LiveRestoreEnabled determines whether containers should be kept
  190. // running when the daemon is shutdown or upon daemon start if
  191. // running containers are detected
  192. LiveRestoreEnabled bool
  193. Isolation container.Isolation
  194. }
  195. // SecurityOpt holds key/value pair about a security option
  196. type SecurityOpt struct {
  197. Key, Value string
  198. }
  199. // Info contains response of Remote API:
  200. // GET "/info"
  201. type Info struct {
  202. *InfoBase
  203. SecurityOptions []SecurityOpt
  204. }
  205. // PluginsInfo is a temp struct holding Plugins name
  206. // registered with docker daemon. It is used by Info struct
  207. type PluginsInfo struct {
  208. // List of Volume plugins registered
  209. Volume []string
  210. // List of Network plugins registered
  211. Network []string
  212. // List of Authorization plugins registered
  213. Authorization []string
  214. }
  215. // ExecStartCheck is a temp struct used by execStart
  216. // Config fields is part of ExecConfig in runconfig package
  217. type ExecStartCheck struct {
  218. // ExecStart will first check if it's detached
  219. Detach bool
  220. // Check if there's a tty
  221. Tty bool
  222. }
  223. // HealthcheckResult stores information about a single run of a healthcheck probe
  224. type HealthcheckResult struct {
  225. Start time.Time // Start is the time this check started
  226. End time.Time // End is the time this check ended
  227. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  228. Output string // Output from last check
  229. }
  230. // Health states
  231. const (
  232. NoHealthcheck = "none" // Indicates there is no healthcheck
  233. Starting = "starting" // Starting indicates that the container is not yet ready
  234. Healthy = "healthy" // Healthy indicates that the container is running correctly
  235. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  236. )
  237. // Health stores information about the container's healthcheck results
  238. type Health struct {
  239. Status string // Status is one of Starting, Healthy or Unhealthy
  240. FailingStreak int // FailingStreak is the number of consecutive failures
  241. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  242. }
  243. // ContainerState stores container's running state
  244. // it's part of ContainerJSONBase and will return by "inspect" command
  245. type ContainerState struct {
  246. Status string
  247. Running bool
  248. Paused bool
  249. Restarting bool
  250. OOMKilled bool
  251. Dead bool
  252. Pid int
  253. ExitCode int
  254. Error string
  255. StartedAt string
  256. FinishedAt string
  257. Health *Health `json:",omitempty"`
  258. }
  259. // ContainerNode stores information about the node that a container
  260. // is running on. It's only available in Docker Swarm
  261. type ContainerNode struct {
  262. ID string
  263. IPAddress string `json:"IP"`
  264. Addr string
  265. Name string
  266. Cpus int
  267. Memory int64
  268. Labels map[string]string
  269. }
  270. // ContainerJSONBase contains response of Remote API:
  271. // GET "/containers/{name:.*}/json"
  272. type ContainerJSONBase struct {
  273. ID string `json:"Id"`
  274. Created string
  275. Path string
  276. Args []string
  277. State *ContainerState
  278. Image string
  279. ResolvConfPath string
  280. HostnamePath string
  281. HostsPath string
  282. LogPath string
  283. Node *ContainerNode `json:",omitempty"`
  284. Name string
  285. RestartCount int
  286. Driver string
  287. MountLabel string
  288. ProcessLabel string
  289. AppArmorProfile string
  290. ExecIDs []string
  291. HostConfig *container.HostConfig
  292. GraphDriver GraphDriverData
  293. SizeRw *int64 `json:",omitempty"`
  294. SizeRootFs *int64 `json:",omitempty"`
  295. }
  296. // ContainerJSON is newly used struct along with MountPoint
  297. type ContainerJSON struct {
  298. *ContainerJSONBase
  299. Mounts []MountPoint
  300. Config *container.Config
  301. NetworkSettings *NetworkSettings
  302. }
  303. // NetworkSettings exposes the network settings in the api
  304. type NetworkSettings struct {
  305. NetworkSettingsBase
  306. DefaultNetworkSettings
  307. Networks map[string]*network.EndpointSettings
  308. }
  309. // SummaryNetworkSettings provides a summary of container's networks
  310. // in /containers/json
  311. type SummaryNetworkSettings struct {
  312. Networks map[string]*network.EndpointSettings
  313. }
  314. // NetworkSettingsBase holds basic information about networks
  315. type NetworkSettingsBase struct {
  316. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  317. SandboxID string // SandboxID uniquely represents a container's network stack
  318. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  319. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  320. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  321. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  322. SandboxKey string // SandboxKey identifies the sandbox
  323. SecondaryIPAddresses []network.Address
  324. SecondaryIPv6Addresses []network.Address
  325. }
  326. // DefaultNetworkSettings holds network information
  327. // during the 2 release deprecation period.
  328. // It will be removed in Docker 1.11.
  329. type DefaultNetworkSettings struct {
  330. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  331. Gateway string // Gateway holds the gateway address for the network
  332. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  333. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  334. IPAddress string // IPAddress holds the IPv4 address for the network
  335. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  336. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  337. MacAddress string // MacAddress holds the MAC address for the network
  338. }
  339. // MountPoint represents a mount point configuration inside the container.
  340. // This is used for reporting the mountpoints in use by a container.
  341. type MountPoint struct {
  342. Type mount.Type `json:",omitempty"`
  343. Name string `json:",omitempty"`
  344. Source string
  345. Destination string
  346. Driver string `json:",omitempty"`
  347. Mode string
  348. RW bool
  349. Propagation mount.Propagation
  350. }
  351. // NetworkResource is the body of the "get network" http response message
  352. type NetworkResource struct {
  353. Name string // Name is the requested name of the network
  354. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  355. Created time.Time // Created is the time the network created
  356. Scope string // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
  357. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  358. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  359. IPAM network.IPAM // IPAM is the network's IP Address Management
  360. Internal bool // Internal represents if the network is used internal only
  361. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  362. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  363. Options map[string]string // Options holds the network specific options to use for when creating the network
  364. Labels map[string]string // Labels holds metadata specific to the network being created
  365. }
  366. // EndpointResource contains network resources allocated and used for a container in a network
  367. type EndpointResource struct {
  368. Name string
  369. EndpointID string
  370. MacAddress string
  371. IPv4Address string
  372. IPv6Address string
  373. }
  374. // NetworkCreate is the expected body of the "create network" http request message
  375. type NetworkCreate struct {
  376. CheckDuplicate bool
  377. Driver string
  378. EnableIPv6 bool
  379. IPAM *network.IPAM
  380. Internal bool
  381. Attachable bool
  382. Options map[string]string
  383. Labels map[string]string
  384. }
  385. // NetworkCreateRequest is the request message sent to the server for network create call.
  386. type NetworkCreateRequest struct {
  387. NetworkCreate
  388. Name string
  389. }
  390. // NetworkCreateResponse is the response message sent by the server for network create call
  391. type NetworkCreateResponse struct {
  392. ID string `json:"Id"`
  393. Warning string
  394. }
  395. // NetworkConnect represents the data to be used to connect a container to the network
  396. type NetworkConnect struct {
  397. Container string
  398. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  399. }
  400. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  401. type NetworkDisconnect struct {
  402. Container string
  403. Force bool
  404. }
  405. // Checkpoint represents the details of a checkpoint
  406. type Checkpoint struct {
  407. Name string // Name is the name of the checkpoint
  408. }
  409. // Runtime describes an OCI runtime
  410. type Runtime struct {
  411. Path string `json:"path"`
  412. Args []string `json:"runtimeArgs,omitempty"`
  413. }
  414. // DiskUsage contains response of Remote API:
  415. // GET "/system/df"
  416. type DiskUsage struct {
  417. LayersSize int64
  418. Images []*ImageSummary
  419. Containers []*Container
  420. Volumes []*Volume
  421. }
  422. // ImagesPruneConfig contains the configuration for Remote API:
  423. // POST "/images/prune"
  424. type ImagesPruneConfig struct {
  425. DanglingOnly bool
  426. }
  427. // ContainersPruneConfig contains the configuration for Remote API:
  428. // POST "/images/prune"
  429. type ContainersPruneConfig struct {
  430. }
  431. // VolumesPruneConfig contains the configuration for Remote API:
  432. // POST "/images/prune"
  433. type VolumesPruneConfig struct {
  434. }
  435. // NetworksPruneConfig contains the configuration for Remote API:
  436. // POST "/networks/prune"
  437. type NetworksPruneConfig struct {
  438. }
  439. // ContainersPruneReport contains the response for Remote API:
  440. // POST "/containers/prune"
  441. type ContainersPruneReport struct {
  442. ContainersDeleted []string
  443. SpaceReclaimed uint64
  444. }
  445. // VolumesPruneReport contains the response for Remote API:
  446. // POST "/volumes/prune"
  447. type VolumesPruneReport struct {
  448. VolumesDeleted []string
  449. SpaceReclaimed uint64
  450. }
  451. // ImagesPruneReport contains the response for Remote API:
  452. // POST "/images/prune"
  453. type ImagesPruneReport struct {
  454. ImagesDeleted []ImageDelete
  455. SpaceReclaimed uint64
  456. }
  457. // NetworksPruneReport contains the response for Remote API:
  458. // POST "/networks/prune"
  459. type NetworksPruneReport struct {
  460. NetworksDeleted []string
  461. }