types.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. }
  226. // ExecStartCheck is a temp struct used by execStart
  227. // Config fields is part of ExecConfig in runconfig package
  228. type ExecStartCheck struct {
  229. // ExecStart will first check if it's detached
  230. Detach bool
  231. // Check if there's a tty
  232. Tty bool
  233. }
  234. // HealthcheckResult stores information about a single run of a healthcheck probe
  235. type HealthcheckResult struct {
  236. Start time.Time // Start is the time this check started
  237. End time.Time // End is the time this check ended
  238. ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
  239. Output string // Output from last check
  240. }
  241. // Health states
  242. const (
  243. NoHealthcheck = "none" // Indicates there is no healthcheck
  244. Starting = "starting" // Starting indicates that the container is not yet ready
  245. Healthy = "healthy" // Healthy indicates that the container is running correctly
  246. Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem
  247. )
  248. // Health stores information about the container's healthcheck results
  249. type Health struct {
  250. Status string // Status is one of Starting, Healthy or Unhealthy
  251. FailingStreak int // FailingStreak is the number of consecutive failures
  252. Log []*HealthcheckResult // Log contains the last few results (oldest first)
  253. }
  254. // ContainerState stores container's running state
  255. // it's part of ContainerJSONBase and will return by "inspect" command
  256. type ContainerState struct {
  257. Status string
  258. Running bool
  259. Paused bool
  260. Restarting bool
  261. OOMKilled bool
  262. Dead bool
  263. Pid int
  264. ExitCode int
  265. Error string
  266. StartedAt string
  267. FinishedAt string
  268. Health *Health `json:",omitempty"`
  269. }
  270. // ContainerNode stores information about the node that a container
  271. // is running on. It's only available in Docker Swarm
  272. type ContainerNode struct {
  273. ID string
  274. IPAddress string `json:"IP"`
  275. Addr string
  276. Name string
  277. Cpus int
  278. Memory int64
  279. Labels map[string]string
  280. }
  281. // ContainerJSONBase contains response of Engine API:
  282. // GET "/containers/{name:.*}/json"
  283. type ContainerJSONBase struct {
  284. ID string `json:"Id"`
  285. Created string
  286. Path string
  287. Args []string
  288. State *ContainerState
  289. Image string
  290. ResolvConfPath string
  291. HostnamePath string
  292. HostsPath string
  293. LogPath string
  294. Node *ContainerNode `json:",omitempty"`
  295. Name string
  296. RestartCount int
  297. Driver string
  298. MountLabel string
  299. ProcessLabel string
  300. AppArmorProfile string
  301. ExecIDs []string
  302. HostConfig *container.HostConfig
  303. GraphDriver GraphDriverData
  304. SizeRw *int64 `json:",omitempty"`
  305. SizeRootFs *int64 `json:",omitempty"`
  306. }
  307. // ContainerJSON is newly used struct along with MountPoint
  308. type ContainerJSON struct {
  309. *ContainerJSONBase
  310. Mounts []MountPoint
  311. Config *container.Config
  312. NetworkSettings *NetworkSettings
  313. }
  314. // NetworkSettings exposes the network settings in the api
  315. type NetworkSettings struct {
  316. NetworkSettingsBase
  317. DefaultNetworkSettings
  318. Networks map[string]*network.EndpointSettings
  319. }
  320. // SummaryNetworkSettings provides a summary of container's networks
  321. // in /containers/json
  322. type SummaryNetworkSettings struct {
  323. Networks map[string]*network.EndpointSettings
  324. }
  325. // NetworkSettingsBase holds basic information about networks
  326. type NetworkSettingsBase struct {
  327. Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`)
  328. SandboxID string // SandboxID uniquely represents a container's network stack
  329. HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
  330. LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
  331. LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
  332. Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
  333. SandboxKey string // SandboxKey identifies the sandbox
  334. SecondaryIPAddresses []network.Address
  335. SecondaryIPv6Addresses []network.Address
  336. }
  337. // DefaultNetworkSettings holds network information
  338. // during the 2 release deprecation period.
  339. // It will be removed in Docker 1.11.
  340. type DefaultNetworkSettings struct {
  341. EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox
  342. Gateway string // Gateway holds the gateway address for the network
  343. GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address
  344. GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
  345. IPAddress string // IPAddress holds the IPv4 address for the network
  346. IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address
  347. IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6
  348. MacAddress string // MacAddress holds the MAC address for the network
  349. }
  350. // MountPoint represents a mount point configuration inside the container.
  351. // This is used for reporting the mountpoints in use by a container.
  352. type MountPoint struct {
  353. Type mount.Type `json:",omitempty"`
  354. Name string `json:",omitempty"`
  355. Source string
  356. Destination string
  357. Driver string `json:",omitempty"`
  358. Mode string
  359. RW bool
  360. Propagation mount.Propagation
  361. }
  362. // NetworkResource is the body of the "get network" http response message
  363. type NetworkResource struct {
  364. Name string // Name is the requested name of the network
  365. ID string `json:"Id"` // ID uniquely identifies a network on a single machine
  366. Created time.Time // Created is the time the network created
  367. Scope string // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level)
  368. Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
  369. EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
  370. IPAM network.IPAM // IPAM is the network's IP Address Management
  371. Internal bool // Internal represents if the network is used internal only
  372. Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
  373. Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
  374. Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
  375. Options map[string]string // Options holds the network specific options to use for when creating the network
  376. Labels map[string]string // Labels holds metadata specific to the network being created
  377. Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
  378. Services map[string]network.ServiceInfo `json:",omitempty"`
  379. }
  380. // EndpointResource contains network resources allocated and used for a container in a network
  381. type EndpointResource struct {
  382. Name string
  383. EndpointID string
  384. MacAddress string
  385. IPv4Address string
  386. IPv6Address string
  387. }
  388. // NetworkCreate is the expected body of the "create network" http request message
  389. type NetworkCreate struct {
  390. // Check for networks with duplicate names.
  391. // Network is primarily keyed based on a random ID and not on the name.
  392. // Network name is strictly a user-friendly alias to the network
  393. // which is uniquely identified using ID.
  394. // And there is no guaranteed way to check for duplicates.
  395. // Option CheckDuplicate is there to provide a best effort checking of any networks
  396. // which has the same name but it is not guaranteed to catch all name collisions.
  397. CheckDuplicate bool
  398. Driver string
  399. EnableIPv6 bool
  400. IPAM *network.IPAM
  401. Internal bool
  402. Attachable bool
  403. Ingress bool
  404. Options map[string]string
  405. Labels map[string]string
  406. }
  407. // NetworkCreateRequest is the request message sent to the server for network create call.
  408. type NetworkCreateRequest struct {
  409. NetworkCreate
  410. Name string
  411. }
  412. // NetworkCreateResponse is the response message sent by the server for network create call
  413. type NetworkCreateResponse struct {
  414. ID string `json:"Id"`
  415. Warning string
  416. }
  417. // NetworkConnect represents the data to be used to connect a container to the network
  418. type NetworkConnect struct {
  419. Container string
  420. EndpointConfig *network.EndpointSettings `json:",omitempty"`
  421. }
  422. // NetworkDisconnect represents the data to be used to disconnect a container from the network
  423. type NetworkDisconnect struct {
  424. Container string
  425. Force bool
  426. }
  427. // Checkpoint represents the details of a checkpoint
  428. type Checkpoint struct {
  429. Name string // Name is the name of the checkpoint
  430. }
  431. // Runtime describes an OCI runtime
  432. type Runtime struct {
  433. Path string `json:"path"`
  434. Args []string `json:"runtimeArgs,omitempty"`
  435. }
  436. // DiskUsage contains response of Engine API:
  437. // GET "/system/df"
  438. type DiskUsage struct {
  439. LayersSize int64
  440. Images []*ImageSummary
  441. Containers []*Container
  442. Volumes []*Volume
  443. }
  444. // ContainersPruneReport contains the response for Engine API:
  445. // POST "/containers/prune"
  446. type ContainersPruneReport struct {
  447. ContainersDeleted []string
  448. SpaceReclaimed uint64
  449. }
  450. // VolumesPruneReport contains the response for Engine API:
  451. // POST "/volumes/prune"
  452. type VolumesPruneReport struct {
  453. VolumesDeleted []string
  454. SpaceReclaimed uint64
  455. }
  456. // ImagesPruneReport contains the response for Engine API:
  457. // POST "/images/prune"
  458. type ImagesPruneReport struct {
  459. ImagesDeleted []ImageDeleteResponseItem
  460. SpaceReclaimed uint64
  461. }
  462. // NetworksPruneReport contains the response for Engine API:
  463. // POST "/networks/prune"
  464. type NetworksPruneReport struct {
  465. NetworksDeleted []string
  466. }
  467. // SecretCreateResponse contains the information returned to a client
  468. // on the creation of a new secret.
  469. type SecretCreateResponse struct {
  470. // ID is the id of the created secret.
  471. ID string
  472. }
  473. // SecretListOptions holds parameters to list secrets
  474. type SecretListOptions struct {
  475. Filters filters.Args
  476. }
  477. // PushResult contains the tag, manifest digest, and manifest size from the
  478. // push. It's used to signal this information to the trust code in the client
  479. // so it can sign the manifest if necessary.
  480. type PushResult struct {
  481. Tag string
  482. Digest string
  483. Size int
  484. }