types.go 16 KB

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