types.go 19 KB

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