types.go 17 KB

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