types.go 17 KB

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