github.com/devdivbcp/moby@v17.12.0-ce-rc1.0.20200726071732-2d4bfdc789ad+incompatible/api/types/types.go (about)

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