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