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