types.go 16 KB

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