types.go 16 KB

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