types.go 19 KB

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