github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/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 // Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
   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  	DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
   215  	Warnings            []string
   216  }
   217  
   218  // KeyValue holds a key/value pair
   219  type KeyValue struct {
   220  	Key, Value string
   221  }
   222  
   223  // NetworkAddressPool is a temp struct used by Info struct
   224  type NetworkAddressPool struct {
   225  	Base string
   226  	Size int
   227  }
   228  
   229  // SecurityOpt contains the name and options of a security option
   230  type SecurityOpt struct {
   231  	Name    string
   232  	Options []KeyValue
   233  }
   234  
   235  // DecodeSecurityOptions decodes a security options string slice to a type safe
   236  // SecurityOpt
   237  func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
   238  	so := []SecurityOpt{}
   239  	for _, opt := range opts {
   240  		// support output from a < 1.13 docker daemon
   241  		if !strings.Contains(opt, "=") {
   242  			so = append(so, SecurityOpt{Name: opt})
   243  			continue
   244  		}
   245  		secopt := SecurityOpt{}
   246  		split := strings.Split(opt, ",")
   247  		for _, s := range split {
   248  			kv := strings.SplitN(s, "=", 2)
   249  			if len(kv) != 2 {
   250  				return nil, fmt.Errorf("invalid security option %q", s)
   251  			}
   252  			if kv[0] == "" || kv[1] == "" {
   253  				return nil, errors.New("invalid empty security option")
   254  			}
   255  			if kv[0] == "name" {
   256  				secopt.Name = kv[1]
   257  				continue
   258  			}
   259  			secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]})
   260  		}
   261  		so = append(so, secopt)
   262  	}
   263  	return so, nil
   264  }
   265  
   266  // PluginsInfo is a temp struct holding Plugins name
   267  // registered with docker daemon. It is used by Info struct
   268  type PluginsInfo struct {
   269  	// List of Volume plugins registered
   270  	Volume []string
   271  	// List of Network plugins registered
   272  	Network []string
   273  	// List of Authorization plugins registered
   274  	Authorization []string
   275  	// List of Log plugins registered
   276  	Log []string
   277  }
   278  
   279  // ExecStartCheck is a temp struct used by execStart
   280  // Config fields is part of ExecConfig in runconfig package
   281  type ExecStartCheck struct {
   282  	// ExecStart will first check if it's detached
   283  	Detach bool
   284  	// Check if there's a tty
   285  	Tty bool
   286  }
   287  
   288  // HealthcheckResult stores information about a single run of a healthcheck probe
   289  type HealthcheckResult struct {
   290  	Start    time.Time // Start is the time this check started
   291  	End      time.Time // End is the time this check ended
   292  	ExitCode int       // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
   293  	Output   string    // Output from last check
   294  }
   295  
   296  // Health states
   297  const (
   298  	NoHealthcheck = "none"      // Indicates there is no healthcheck
   299  	Starting      = "starting"  // Starting indicates that the container is not yet ready
   300  	Healthy       = "healthy"   // Healthy indicates that the container is running correctly
   301  	Unhealthy     = "unhealthy" // Unhealthy indicates that the container has a problem
   302  )
   303  
   304  // Health stores information about the container's healthcheck results
   305  type Health struct {
   306  	Status        string               // Status is one of Starting, Healthy or Unhealthy
   307  	FailingStreak int                  // FailingStreak is the number of consecutive failures
   308  	Log           []*HealthcheckResult // Log contains the last few results (oldest first)
   309  }
   310  
   311  // ContainerState stores container's running state
   312  // it's part of ContainerJSONBase and will return by "inspect" command
   313  type ContainerState struct {
   314  	Status     string // String representation of the container state. Can be one of "created", "running", "paused", "restarting", "removing", "exited", or "dead"
   315  	Running    bool
   316  	Paused     bool
   317  	Restarting bool
   318  	OOMKilled  bool
   319  	Dead       bool
   320  	Pid        int
   321  	ExitCode   int
   322  	Error      string
   323  	StartedAt  string
   324  	FinishedAt string
   325  	Health     *Health `json:",omitempty"`
   326  }
   327  
   328  // ContainerNode stores information about the node that a container
   329  // is running on.  It's only used by the Docker Swarm standalone API
   330  type ContainerNode struct {
   331  	ID        string
   332  	IPAddress string `json:"IP"`
   333  	Addr      string
   334  	Name      string
   335  	Cpus      int
   336  	Memory    int64
   337  	Labels    map[string]string
   338  }
   339  
   340  // ContainerJSONBase contains response of Engine API:
   341  // GET "/containers/{name:.*}/json"
   342  type ContainerJSONBase struct {
   343  	ID              string `json:"Id"`
   344  	Created         string
   345  	Path            string
   346  	Args            []string
   347  	State           *ContainerState
   348  	Image           string
   349  	ResolvConfPath  string
   350  	HostnamePath    string
   351  	HostsPath       string
   352  	LogPath         string
   353  	Node            *ContainerNode `json:",omitempty"` // Node is only propagated by Docker Swarm standalone API
   354  	Name            string
   355  	RestartCount    int
   356  	Driver          string
   357  	Platform        string
   358  	MountLabel      string
   359  	ProcessLabel    string
   360  	AppArmorProfile string
   361  	ExecIDs         []string
   362  	HostConfig      *container.HostConfig
   363  	GraphDriver     GraphDriverData
   364  	SizeRw          *int64 `json:",omitempty"`
   365  	SizeRootFs      *int64 `json:",omitempty"`
   366  }
   367  
   368  // ContainerJSON is newly used struct along with MountPoint
   369  type ContainerJSON struct {
   370  	*ContainerJSONBase
   371  	Mounts          []MountPoint
   372  	Config          *container.Config
   373  	NetworkSettings *NetworkSettings
   374  }
   375  
   376  // NetworkSettings exposes the network settings in the api
   377  type NetworkSettings struct {
   378  	NetworkSettingsBase
   379  	DefaultNetworkSettings
   380  	Networks map[string]*network.EndpointSettings
   381  }
   382  
   383  // SummaryNetworkSettings provides a summary of container's networks
   384  // in /containers/json
   385  type SummaryNetworkSettings struct {
   386  	Networks map[string]*network.EndpointSettings
   387  }
   388  
   389  // NetworkSettingsBase holds basic information about networks
   390  type NetworkSettingsBase struct {
   391  	Bridge                 string      // Bridge is the Bridge name the network uses(e.g. `docker0`)
   392  	SandboxID              string      // SandboxID uniquely represents a container's network stack
   393  	HairpinMode            bool        // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
   394  	LinkLocalIPv6Address   string      // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix
   395  	LinkLocalIPv6PrefixLen int         // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address
   396  	Ports                  nat.PortMap // Ports is a collection of PortBinding indexed by Port
   397  	SandboxKey             string      // SandboxKey identifies the sandbox
   398  	SecondaryIPAddresses   []network.Address
   399  	SecondaryIPv6Addresses []network.Address
   400  }
   401  
   402  // DefaultNetworkSettings holds network information
   403  // during the 2 release deprecation period.
   404  // It will be removed in Docker 1.11.
   405  type DefaultNetworkSettings struct {
   406  	EndpointID          string // EndpointID uniquely represents a service endpoint in a Sandbox
   407  	Gateway             string // Gateway holds the gateway address for the network
   408  	GlobalIPv6Address   string // GlobalIPv6Address holds network's global IPv6 address
   409  	GlobalIPv6PrefixLen int    // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address
   410  	IPAddress           string // IPAddress holds the IPv4 address for the network
   411  	IPPrefixLen         int    // IPPrefixLen represents mask length of network's IPv4 address
   412  	IPv6Gateway         string // IPv6Gateway holds gateway address specific for IPv6
   413  	MacAddress          string // MacAddress holds the MAC address for the network
   414  }
   415  
   416  // MountPoint represents a mount point configuration inside the container.
   417  // This is used for reporting the mountpoints in use by a container.
   418  type MountPoint struct {
   419  	Type        mount.Type `json:",omitempty"`
   420  	Name        string     `json:",omitempty"`
   421  	Source      string
   422  	Destination string
   423  	Driver      string `json:",omitempty"`
   424  	Mode        string
   425  	RW          bool
   426  	Propagation mount.Propagation
   427  }
   428  
   429  // NetworkResource is the body of the "get network" http response message
   430  type NetworkResource struct {
   431  	Name       string                         // Name is the requested name of the network
   432  	ID         string                         `json:"Id"` // ID uniquely identifies a network on a single machine
   433  	Created    time.Time                      // Created is the time the network created
   434  	Scope      string                         // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
   435  	Driver     string                         // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
   436  	EnableIPv6 bool                           // EnableIPv6 represents whether to enable IPv6
   437  	IPAM       network.IPAM                   // IPAM is the network's IP Address Management
   438  	Internal   bool                           // Internal represents if the network is used internal only
   439  	Attachable bool                           // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
   440  	Ingress    bool                           // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
   441  	ConfigFrom network.ConfigReference        // ConfigFrom specifies the source which will provide the configuration for this network.
   442  	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.
   443  	Containers map[string]EndpointResource    // Containers contains endpoints belonging to the network
   444  	Options    map[string]string              // Options holds the network specific options to use for when creating the network
   445  	Labels     map[string]string              // Labels holds metadata specific to the network being created
   446  	Peers      []network.PeerInfo             `json:",omitempty"` // List of peer nodes for an overlay network
   447  	Services   map[string]network.ServiceInfo `json:",omitempty"`
   448  }
   449  
   450  // EndpointResource contains network resources allocated and used for a container in a network
   451  type EndpointResource struct {
   452  	Name        string
   453  	EndpointID  string
   454  	MacAddress  string
   455  	IPv4Address string
   456  	IPv6Address string
   457  }
   458  
   459  // NetworkCreate is the expected body of the "create network" http request message
   460  type NetworkCreate struct {
   461  	// Check for networks with duplicate names.
   462  	// Network is primarily keyed based on a random ID and not on the name.
   463  	// Network name is strictly a user-friendly alias to the network
   464  	// which is uniquely identified using ID.
   465  	// And there is no guaranteed way to check for duplicates.
   466  	// Option CheckDuplicate is there to provide a best effort checking of any networks
   467  	// which has the same name but it is not guaranteed to catch all name collisions.
   468  	CheckDuplicate bool
   469  	Driver         string
   470  	Scope          string
   471  	EnableIPv6     bool
   472  	IPAM           *network.IPAM
   473  	Internal       bool
   474  	Attachable     bool
   475  	Ingress        bool
   476  	ConfigOnly     bool
   477  	ConfigFrom     *network.ConfigReference
   478  	Options        map[string]string
   479  	Labels         map[string]string
   480  }
   481  
   482  // NetworkCreateRequest is the request message sent to the server for network create call.
   483  type NetworkCreateRequest struct {
   484  	NetworkCreate
   485  	Name string
   486  }
   487  
   488  // NetworkCreateResponse is the response message sent by the server for network create call
   489  type NetworkCreateResponse struct {
   490  	ID      string `json:"Id"`
   491  	Warning string
   492  }
   493  
   494  // NetworkConnect represents the data to be used to connect a container to the network
   495  type NetworkConnect struct {
   496  	Container      string
   497  	EndpointConfig *network.EndpointSettings `json:",omitempty"`
   498  }
   499  
   500  // NetworkDisconnect represents the data to be used to disconnect a container from the network
   501  type NetworkDisconnect struct {
   502  	Container string
   503  	Force     bool
   504  }
   505  
   506  // NetworkInspectOptions holds parameters to inspect network
   507  type NetworkInspectOptions struct {
   508  	Scope   string
   509  	Verbose bool
   510  }
   511  
   512  // Checkpoint represents the details of a checkpoint
   513  type Checkpoint struct {
   514  	Name string // Name is the name of the checkpoint
   515  }
   516  
   517  // Runtime describes an OCI runtime
   518  type Runtime struct {
   519  	Path string   `json:"path"`
   520  	Args []string `json:"runtimeArgs,omitempty"`
   521  
   522  	// This is exposed here only for internal use
   523  	// It is not currently supported to specify custom shim configs
   524  	Shim *ShimConfig `json:"-"`
   525  }
   526  
   527  // ShimConfig is used by runtime to configure containerd shims
   528  type ShimConfig struct {
   529  	Binary string
   530  	Opts   interface{}
   531  }
   532  
   533  // DiskUsage contains response of Engine API:
   534  // GET "/system/df"
   535  type DiskUsage struct {
   536  	LayersSize  int64
   537  	Images      []*ImageSummary
   538  	Containers  []*Container
   539  	Volumes     []*Volume
   540  	BuildCache  []*BuildCache
   541  	BuilderSize int64 // deprecated
   542  }
   543  
   544  // ContainersPruneReport contains the response for Engine API:
   545  // POST "/containers/prune"
   546  type ContainersPruneReport struct {
   547  	ContainersDeleted []string
   548  	SpaceReclaimed    uint64
   549  }
   550  
   551  // VolumesPruneReport contains the response for Engine API:
   552  // POST "/volumes/prune"
   553  type VolumesPruneReport struct {
   554  	VolumesDeleted []string
   555  	SpaceReclaimed uint64
   556  }
   557  
   558  // ImagesPruneReport contains the response for Engine API:
   559  // POST "/images/prune"
   560  type ImagesPruneReport struct {
   561  	ImagesDeleted  []ImageDeleteResponseItem
   562  	SpaceReclaimed uint64
   563  }
   564  
   565  // BuildCachePruneReport contains the response for Engine API:
   566  // POST "/build/prune"
   567  type BuildCachePruneReport struct {
   568  	CachesDeleted  []string
   569  	SpaceReclaimed uint64
   570  }
   571  
   572  // NetworksPruneReport contains the response for Engine API:
   573  // POST "/networks/prune"
   574  type NetworksPruneReport struct {
   575  	NetworksDeleted []string
   576  }
   577  
   578  // SecretCreateResponse contains the information returned to a client
   579  // on the creation of a new secret.
   580  type SecretCreateResponse struct {
   581  	// ID is the id of the created secret.
   582  	ID string
   583  }
   584  
   585  // SecretListOptions holds parameters to list secrets
   586  type SecretListOptions struct {
   587  	Filters filters.Args
   588  }
   589  
   590  // ConfigCreateResponse contains the information returned to a client
   591  // on the creation of a new config.
   592  type ConfigCreateResponse struct {
   593  	// ID is the id of the created config.
   594  	ID string
   595  }
   596  
   597  // ConfigListOptions holds parameters to list configs
   598  type ConfigListOptions struct {
   599  	Filters filters.Args
   600  }
   601  
   602  // PushResult contains the tag, manifest digest, and manifest size from the
   603  // push. It's used to signal this information to the trust code in the client
   604  // so it can sign the manifest if necessary.
   605  type PushResult struct {
   606  	Tag    string
   607  	Digest string
   608  	Size   int
   609  }
   610  
   611  // BuildResult contains the image id of a successful build
   612  type BuildResult struct {
   613  	ID string
   614  }
   615  
   616  // BuildCache contains information about a build cache record
   617  type BuildCache struct {
   618  	ID          string
   619  	Parent      string
   620  	Type        string
   621  	Description string
   622  	InUse       bool
   623  	Shared      bool
   624  	Size        int64
   625  	CreatedAt   time.Time
   626  	LastUsedAt  *time.Time
   627  	UsageCount  int
   628  }
   629  
   630  // BuildCachePruneOptions hold parameters to prune the build cache
   631  type BuildCachePruneOptions struct {
   632  	All         bool
   633  	KeepStorage int64
   634  	Filters     filters.Args
   635  }