types.go 17 KB

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