types.go 19 KB

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