types.go 18 KB

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