types.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. // Ping contains response of Engine API:
  88. // GET "/_ping"
  89. type Ping struct {
  90. APIVersion string
  91. OSType string
  92. Experimental bool
  93. }
  94. // Version contains response of Engine API:
  95. // GET "/version"
  96. type Version struct {
  97. Version string
  98. APIVersion string `json:"ApiVersion"`
  99. MinAPIVersion string `json:"MinAPIVersion,omitempty"`
  100. GitCommit string
  101. GoVersion string
  102. Os string
  103. Arch string
  104. KernelVersion string `json:",omitempty"`
  105. Experimental bool `json:",omitempty"`
  106. BuildTime string `json:",omitempty"`
  107. }
  108. // Commit holds the Git-commit (SHA1) that a binary was built from, as reported
  109. // in the version-string of external tools, such as containerd, or runC.
  110. type Commit struct {
  111. ID string // ID is the actual commit ID of external tool.
  112. Expected string // Expected is the commit ID of external tool expected by dockerd as set at build time.
  113. }
  114. // Info contains response of Engine API:
  115. // GET "/info"
  116. type Info struct {
  117. ID string
  118. Containers int
  119. ContainersRunning int
  120. ContainersPaused int
  121. ContainersStopped int
  122. Images int
  123. Driver string
  124. DriverStatus [][2]string
  125. SystemStatus [][2]string
  126. Plugins PluginsInfo
  127. MemoryLimit bool
  128. SwapLimit bool
  129. KernelMemory bool
  130. CPUCfsPeriod bool `json:"CpuCfsPeriod"`
  131. CPUCfsQuota bool `json:"CpuCfsQuota"`
  132. CPUShares bool
  133. CPUSet bool
  134. IPv4Forwarding bool
  135. BridgeNfIptables bool
  136. BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
  137. Debug bool
  138. NFd int
  139. OomKillDisable bool
  140. NGoroutines int
  141. SystemTime string
  142. LoggingDriver string
  143. CgroupDriver string
  144. NEventsListener int
  145. KernelVersion string
  146. OperatingSystem string
  147. OSType string
  148. Architecture string
  149. IndexServerAddress string
  150. RegistryConfig *registry.ServiceConfig
  151. NCPU int
  152. MemTotal int64
  153. DockerRootDir string
  154. HTTPProxy string `json:"HttpProxy"`
  155. HTTPSProxy string `json:"HttpsProxy"`
  156. NoProxy string
  157. Name string
  158. Labels []string
  159. ExperimentalBuild bool
  160. ServerVersion string
  161. ClusterStore string
  162. ClusterAdvertise string
  163. Runtimes map[string]Runtime
  164. DefaultRuntime string
  165. Swarm swarm.Info
  166. // LiveRestoreEnabled determines whether containers should be kept
  167. // running when the daemon is shutdown or upon daemon start if
  168. // running containers are detected
  169. LiveRestoreEnabled bool
  170. Isolation container.Isolation
  171. InitBinary string
  172. ContainerdCommit Commit
  173. RuncCommit Commit
  174. InitCommit Commit
  175. SecurityOptions []string
  176. }
  177. // KeyValue holds a key/value pair
  178. type KeyValue struct {
  179. Key, Value string
  180. }
  181. // SecurityOpt contains the name and options of a security option
  182. type SecurityOpt struct {
  183. Name string
  184. Options []KeyValue
  185. }
  186. // DecodeSecurityOptions decodes a security options string slice to a type safe
  187. // SecurityOpt
  188. func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
  189. so := []SecurityOpt{}
  190. for _, opt := range opts {
  191. // support output from a < 1.13 docker daemon
  192. if !strings.Contains(opt, "=") {
  193. so = append(so, SecurityOpt{Name: opt})
  194. continue
  195. }
  196. secopt := SecurityOpt{}
  197. split := strings.Split(opt, ",")
  198. for _, s := range split {
  199. kv := strings.SplitN(s, "=", 2)
  200. if len(kv) != 2 {
  201. return nil, fmt.Errorf("invalid security option %q", s)
  202. }
  203. if kv[0] == "" || kv[1] == "" {
  204. return nil, errors.New("invalid empty security option")
  205. }
  206. if kv[0] == "name" {
  207. secopt.Name = kv[1]
  208. continue
  209. }
  210. secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]})
  211. }
  212. so = append(so, secopt)
  213. }
  214. return so, nil
  215. }
  216. // PluginsInfo is a temp struct holding Plugins name
  217. // registered with docker daemon. It is used by Info struct
  218. type PluginsInfo struct {
  219. // List of Volume plugins registered
  220. Volume []string
  221. // List of Network plugins registered
  222. Network []string
  223. // List of Authorization plugins registered
  224. Authorization []string
  225. // List of Log plugins registered
  226. Log []string
  227. }
  228. // ExecStartCheck is a temp struct used by execStart
  229. // Config fields is part of ExecConfig in runconfig package
  230. type ExecStartCheck struct {
  231. // ExecStart will first check if it's detached
  232. Detach bool
  233. // Check if there's a tty
  234. Tty bool
  235. }
  236. // HealthcheckResult stores information about a single run of a healthcheck probe
  237. type HealthcheckResult struct {
  238. Start time.Time // Start is the time this check started
  239. End time.Time // End is the time this check ended
  240. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  241. Output string // Output from last check
  242. }
  243. // Health states
  244. const (
  245. NoHealthcheck = "none" // Indicates there is no healthcheck
  246. Starting = "starting" // Starting indicates that the container is not yet ready
  247. Healthy = "healthy" // Healthy indicates that the container is running correctly
  248. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  249. )
  250. // Health stores information about the container's healthcheck results
  251. type Health struct {
  252. Status string // Status is one of Starting, Healthy or Unhealthy
  253. FailingStreak int // FailingStreak is the number of consecutive failures
  254. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  255. }
  256. // ContainerState stores container's running state
  257. // it's part of ContainerJSONBase and will return by "inspect" command
  258. type ContainerState struct {
  259. Status string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
  260. Running bool
  261. Paused bool
  262. Restarting bool
  263. OOMKilled bool
  264. Dead bool
  265. Pid int
  266. ExitCode int
  267. Error string
  268. StartedAt string
  269. FinishedAt string
  270. Health *Health `json:",omitempty"`
  271. }
  272. // ContainerNode stores information about the node that a container
  273. // is running on. It's only available in Docker Swarm
  274. type ContainerNode struct {
  275. ID string
  276. IPAddress string `json:"IP"`
  277. Addr string
  278. Name string
  279. Cpus int
  280. Memory int64
  281. Labels map[string]string
  282. }
  283. // ContainerJSONBase contains response of Engine API:
  284. // GET "/containers/{name:.*}/json"
  285. type ContainerJSONBase struct {
  286. ID string `json:"Id"`
  287. Created string
  288. Path string
  289. Args []string
  290. State *ContainerState
  291. Image string
  292. ResolvConfPath string
  293. HostnamePath string
  294. HostsPath string
  295. LogPath string
  296. Node *ContainerNode `json:",omitempty"`
  297. Name string
  298. RestartCount int
  299. Driver string
  300. MountLabel string
  301. ProcessLabel string
  302. AppArmorProfile string
  303. ExecIDs []string
  304. HostConfig *container.HostConfig
  305. GraphDriver GraphDriverData
  306. SizeRw *int64 `json:",omitempty"`
  307. SizeRootFs *int64 `json:",omitempty"`
  308. }
  309. // ContainerJSON is newly used struct along with MountPoint
  310. type ContainerJSON struct {
  311. *ContainerJSONBase
  312. Mounts []MountPoint
  313. Config *container.Config
  314. NetworkSettings *NetworkSettings
  315. }
  316. // NetworkSettings exposes the network settings in the api
  317. type NetworkSettings struct {
  318. NetworkSettingsBase
  319. DefaultNetworkSettings
  320. Networks map[string]*network.EndpointSettings
  321. }
  322. // SummaryNetworkSettings provides a summary of container's networks
  323. // in /containers/json
  324. type SummaryNetworkSettings struct {
  325. Networks map[string]*network.EndpointSettings
  326. }
  327. // NetworkSettingsBase holds basic information about networks
  328. type NetworkSettingsBase struct {
  329. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  330. SandboxID string // SandboxID uniquely represents a container's network stack
  331. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  332. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  333. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  334. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  335. SandboxKey string // SandboxKey identifies the sandbox
  336. SecondaryIPAddresses []network.Address
  337. SecondaryIPv6Addresses []network.Address
  338. }
  339. // DefaultNetworkSettings holds network information
  340. // during the 2 release deprecation period.
  341. // It will be removed in Docker 1.11.
  342. type DefaultNetworkSettings struct {
  343. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  344. Gateway string // Gateway holds the gateway address for the network
  345. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  346. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  347. IPAddress string // IPAddress holds the IPv4 address for the network
  348. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  349. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  350. MacAddress string // MacAddress holds the MAC address for the network
  351. }
  352. // MountPoint represents a mount point configuration inside the container.
  353. // This is used for reporting the mountpoints in use by a container.
  354. type MountPoint struct {
  355. Type mount.Type `json:",omitempty"`
  356. Name string `json:",omitempty"`
  357. Source string
  358. Destination string
  359. Driver string `json:",omitempty"`
  360. Mode string
  361. RW bool
  362. Propagation mount.Propagation
  363. }
  364. // NetworkResource is the body of the "get network" http response message
  365. type NetworkResource struct {
  366. Name string // Name is the requested name of the network
  367. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  368. Created time.Time // Created is the time the network created
  369. Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
  370. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  371. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  372. IPAM network.IPAM // IPAM is the network's IP Address Management
  373. Internal bool // Internal represents if the network is used internal only
  374. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  375. Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
  376. ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
  377. ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
  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. Services map[string]network.ServiceInfo `json:",omitempty"`
  383. }
  384. // EndpointResource contains network resources allocated and used for a container in a network
  385. type EndpointResource struct {
  386. Name string
  387. EndpointID string
  388. MacAddress string
  389. IPv4Address string
  390. IPv6Address string
  391. }
  392. // NetworkCreate is the expected body of the "create network" http request message
  393. type NetworkCreate struct {
  394. // Check for networks with duplicate names.
  395. // Network is primarily keyed based on a random ID and not on the name.
  396. // Network name is strictly a user-friendly alias to the network
  397. // which is uniquely identified using ID.
  398. // And there is no guaranteed way to check for duplicates.
  399. // Option CheckDuplicate is there to provide a best effort checking of any networks
  400. // which has the same name but it is not guaranteed to catch all name collisions.
  401. CheckDuplicate bool
  402. Driver string
  403. Scope string
  404. EnableIPv6 bool
  405. IPAM *network.IPAM
  406. Internal bool
  407. Attachable bool
  408. Ingress bool
  409. ConfigOnly bool
  410. ConfigFrom *network.ConfigReference
  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. // NetworkInspectOptions holds parameters to inspect network
  435. type NetworkInspectOptions struct {
  436. Scope string
  437. Verbose bool
  438. }
  439. // Checkpoint represents the details of a checkpoint
  440. type Checkpoint struct {
  441. Name string // Name is the name of the checkpoint
  442. }
  443. // Runtime describes an OCI runtime
  444. type Runtime struct {
  445. Path string `json:"path"`
  446. Args []string `json:"runtimeArgs,omitempty"`
  447. }
  448. // DiskUsage contains response of Engine API:
  449. // GET "/system/df"
  450. type DiskUsage struct {
  451. LayersSize int64
  452. Images []*ImageSummary
  453. Containers []*Container
  454. Volumes []*Volume
  455. }
  456. // ContainersPruneReport contains the response for Engine API:
  457. // POST "/containers/prune"
  458. type ContainersPruneReport struct {
  459. ContainersDeleted []string
  460. SpaceReclaimed uint64
  461. }
  462. // VolumesPruneReport contains the response for Engine API:
  463. // POST "/volumes/prune"
  464. type VolumesPruneReport struct {
  465. VolumesDeleted []string
  466. SpaceReclaimed uint64
  467. }
  468. // ImagesPruneReport contains the response for Engine API:
  469. // POST "/images/prune"
  470. type ImagesPruneReport struct {
  471. ImagesDeleted []ImageDeleteResponseItem
  472. SpaceReclaimed uint64
  473. }
  474. // NetworksPruneReport contains the response for Engine API:
  475. // POST "/networks/prune"
  476. type NetworksPruneReport struct {
  477. NetworksDeleted []string
  478. }
  479. // SecretCreateResponse contains the information returned to a client
  480. // on the creation of a new secret.
  481. type SecretCreateResponse struct {
  482. // ID is the id of the created secret.
  483. ID string
  484. }
  485. // SecretListOptions holds parameters to list secrets
  486. type SecretListOptions struct {
  487. Filters filters.Args
  488. }
  489. // ConfigCreateResponse contains the information returned to a client
  490. // on the creation of a new config.
  491. type ConfigCreateResponse struct {
  492. // ID is the id of the created config.
  493. ID string
  494. }
  495. // ConfigListOptions holds parameters to list configs
  496. type ConfigListOptions struct {
  497. Filters filters.Args
  498. }
  499. // PushResult contains the tag, manifest digest, and manifest size from the
  500. // push. It's used to signal this information to the trust code in the client
  501. // so it can sign the manifest if necessary.
  502. type PushResult struct {
  503. Tag string
  504. Digest string
  505. Size int
  506. }
  507. // BuildResult contains the image id of a successful build
  508. type BuildResult struct {
  509. ID string
  510. }