types.go 17 KB

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