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