podman
597 строк · 38.1 Кб
1// Copyright 2013 go-dockerclient authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package docker
6
7import (
8"fmt"
9"strconv"
10"strings"
11"time"
12
13units "github.com/docker/go-units"
14)
15
16// APIPort is a type that represents a port mapping returned by the Docker API
17type APIPort struct {
18PrivatePort int64 `json:"PrivatePort,omitempty" yaml:"PrivatePort,omitempty" toml:"PrivatePort,omitempty"`
19PublicPort int64 `json:"PublicPort,omitempty" yaml:"PublicPort,omitempty" toml:"PublicPort,omitempty"`
20Type string `json:"Type,omitempty" yaml:"Type,omitempty" toml:"Type,omitempty"`
21IP string `json:"IP,omitempty" yaml:"IP,omitempty" toml:"IP,omitempty"`
22}
23
24// APIMount represents a mount point for a container.
25type APIMount struct {
26Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
27Source string `json:"Source,omitempty" yaml:"Source,omitempty" toml:"Source,omitempty"`
28Destination string `json:"Destination,omitempty" yaml:"Destination,omitempty" toml:"Destination,omitempty"`
29Driver string `json:"Driver,omitempty" yaml:"Driver,omitempty" toml:"Driver,omitempty"`
30Mode string `json:"Mode,omitempty" yaml:"Mode,omitempty" toml:"Mode,omitempty"`
31RW bool `json:"RW,omitempty" yaml:"RW,omitempty" toml:"RW,omitempty"`
32Propagation string `json:"Propagation,omitempty" yaml:"Propagation,omitempty" toml:"Propagation,omitempty"`
33Type string `json:"Type,omitempty" yaml:"Type,omitempty" toml:"Type,omitempty"`
34}
35
36// APIContainers represents each container in the list returned by
37// ListContainers.
38type APIContainers struct {
39ID string `json:"Id" yaml:"Id" toml:"Id"`
40Image string `json:"Image,omitempty" yaml:"Image,omitempty" toml:"Image,omitempty"`
41Command string `json:"Command,omitempty" yaml:"Command,omitempty" toml:"Command,omitempty"`
42Created int64 `json:"Created,omitempty" yaml:"Created,omitempty" toml:"Created,omitempty"`
43State string `json:"State,omitempty" yaml:"State,omitempty" toml:"State,omitempty"`
44Status string `json:"Status,omitempty" yaml:"Status,omitempty" toml:"Status,omitempty"`
45Ports []APIPort `json:"Ports,omitempty" yaml:"Ports,omitempty" toml:"Ports,omitempty"`
46SizeRw int64 `json:"SizeRw,omitempty" yaml:"SizeRw,omitempty" toml:"SizeRw,omitempty"`
47SizeRootFs int64 `json:"SizeRootFs,omitempty" yaml:"SizeRootFs,omitempty" toml:"SizeRootFs,omitempty"`
48Names []string `json:"Names,omitempty" yaml:"Names,omitempty" toml:"Names,omitempty"`
49Labels map[string]string `json:"Labels,omitempty" yaml:"Labels,omitempty" toml:"Labels,omitempty"`
50Networks NetworkList `json:"NetworkSettings,omitempty" yaml:"NetworkSettings,omitempty" toml:"NetworkSettings,omitempty"`
51Mounts []APIMount `json:"Mounts,omitempty" yaml:"Mounts,omitempty" toml:"Mounts,omitempty"`
52}
53
54// NetworkList encapsulates a map of networks, as returned by the Docker API in
55// ListContainers.
56type NetworkList struct {
57Networks map[string]ContainerNetwork `json:"Networks" yaml:"Networks,omitempty" toml:"Networks,omitempty"`
58}
59
60// Port represents the port number and the protocol, in the form
61// <number>/<protocol>. For example: 80/tcp.
62type Port string
63
64// Port returns the number of the port.
65func (p Port) Port() string {
66return strings.Split(string(p), "/")[0]
67}
68
69// Proto returns the name of the protocol.
70func (p Port) Proto() string {
71parts := strings.Split(string(p), "/")
72if len(parts) == 1 {
73return "tcp"
74}
75return parts[1]
76}
77
78// HealthCheck represents one check of health.
79type HealthCheck struct {
80Start time.Time `json:"Start,omitempty" yaml:"Start,omitempty" toml:"Start,omitempty"`
81End time.Time `json:"End,omitempty" yaml:"End,omitempty" toml:"End,omitempty"`
82ExitCode int `json:"ExitCode,omitempty" yaml:"ExitCode,omitempty" toml:"ExitCode,omitempty"`
83Output string `json:"Output,omitempty" yaml:"Output,omitempty" toml:"Output,omitempty"`
84}
85
86// Health represents the health of a container.
87type Health struct {
88Status string `json:"Status,omitempty" yaml:"Status,omitempty" toml:"Status,omitempty"`
89FailingStreak int `json:"FailingStreak,omitempty" yaml:"FailingStreak,omitempty" toml:"FailingStreak,omitempty"`
90Log []HealthCheck `json:"Log,omitempty" yaml:"Log,omitempty" toml:"Log,omitempty"`
91}
92
93// State represents the state of a container.
94type State struct {
95Status string `json:"Status,omitempty" yaml:"Status,omitempty" toml:"Status,omitempty"`
96Running bool `json:"Running,omitempty" yaml:"Running,omitempty" toml:"Running,omitempty"`
97Paused bool `json:"Paused,omitempty" yaml:"Paused,omitempty" toml:"Paused,omitempty"`
98Restarting bool `json:"Restarting,omitempty" yaml:"Restarting,omitempty" toml:"Restarting,omitempty"`
99OOMKilled bool `json:"OOMKilled,omitempty" yaml:"OOMKilled,omitempty" toml:"OOMKilled,omitempty"`
100RemovalInProgress bool `json:"RemovalInProgress,omitempty" yaml:"RemovalInProgress,omitempty" toml:"RemovalInProgress,omitempty"`
101Dead bool `json:"Dead,omitempty" yaml:"Dead,omitempty" toml:"Dead,omitempty"`
102Pid int `json:"Pid,omitempty" yaml:"Pid,omitempty" toml:"Pid,omitempty"`
103ExitCode int `json:"ExitCode,omitempty" yaml:"ExitCode,omitempty" toml:"ExitCode,omitempty"`
104Error string `json:"Error,omitempty" yaml:"Error,omitempty" toml:"Error,omitempty"`
105StartedAt time.Time `json:"StartedAt,omitempty" yaml:"StartedAt,omitempty" toml:"StartedAt,omitempty"`
106FinishedAt time.Time `json:"FinishedAt,omitempty" yaml:"FinishedAt,omitempty" toml:"FinishedAt,omitempty"`
107Health Health `json:"Health,omitempty" yaml:"Health,omitempty" toml:"Health,omitempty"`
108}
109
110// String returns a human-readable description of the state
111func (s *State) String() string {
112if s.Running {
113if s.Paused {
114return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
115}
116if s.Restarting {
117return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
118}
119
120return fmt.Sprintf("Up %s", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
121}
122
123if s.RemovalInProgress {
124return "Removal In Progress"
125}
126
127if s.Dead {
128return "Dead"
129}
130
131if s.StartedAt.IsZero() {
132return "Created"
133}
134
135if s.FinishedAt.IsZero() {
136return ""
137}
138
139return fmt.Sprintf("Exited (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
140}
141
142// StateString returns a single string to describe state
143func (s *State) StateString() string {
144if s.Running {
145if s.Paused {
146return "paused"
147}
148if s.Restarting {
149return "restarting"
150}
151return "running"
152}
153
154if s.Dead {
155return "dead"
156}
157
158if s.StartedAt.IsZero() {
159return "created"
160}
161
162return "exited"
163}
164
165// PortBinding represents the host/container port mapping as returned in the
166// `docker inspect` json
167type PortBinding struct {
168HostIP string `json:"HostIp,omitempty" yaml:"HostIp,omitempty" toml:"HostIp,omitempty"`
169HostPort string `json:"HostPort,omitempty" yaml:"HostPort,omitempty" toml:"HostPort,omitempty"`
170}
171
172// PortMapping represents a deprecated field in the `docker inspect` output,
173// and its value as found in NetworkSettings should always be nil
174type PortMapping map[string]string
175
176// ContainerNetwork represents the networking settings of a container per network.
177type ContainerNetwork struct {
178Aliases []string `json:"Aliases,omitempty" yaml:"Aliases,omitempty" toml:"Aliases,omitempty"`
179MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty" toml:"MacAddress,omitempty"`
180GlobalIPv6PrefixLen int `json:"GlobalIPv6PrefixLen,omitempty" yaml:"GlobalIPv6PrefixLen,omitempty" toml:"GlobalIPv6PrefixLen,omitempty"`
181GlobalIPv6Address string `json:"GlobalIPv6Address,omitempty" yaml:"GlobalIPv6Address,omitempty" toml:"GlobalIPv6Address,omitempty"`
182IPv6Gateway string `json:"IPv6Gateway,omitempty" yaml:"IPv6Gateway,omitempty" toml:"IPv6Gateway,omitempty"`
183IPPrefixLen int `json:"IPPrefixLen,omitempty" yaml:"IPPrefixLen,omitempty" toml:"IPPrefixLen,omitempty"`
184IPAddress string `json:"IPAddress,omitempty" yaml:"IPAddress,omitempty" toml:"IPAddress,omitempty"`
185Gateway string `json:"Gateway,omitempty" yaml:"Gateway,omitempty" toml:"Gateway,omitempty"`
186EndpointID string `json:"EndpointID,omitempty" yaml:"EndpointID,omitempty" toml:"EndpointID,omitempty"`
187NetworkID string `json:"NetworkID,omitempty" yaml:"NetworkID,omitempty" toml:"NetworkID,omitempty"`
188}
189
190// NetworkSettings contains network-related information about a container
191type NetworkSettings struct {
192Networks map[string]ContainerNetwork `json:"Networks,omitempty" yaml:"Networks,omitempty" toml:"Networks,omitempty"`
193IPAddress string `json:"IPAddress,omitempty" yaml:"IPAddress,omitempty" toml:"IPAddress,omitempty"`
194IPPrefixLen int `json:"IPPrefixLen,omitempty" yaml:"IPPrefixLen,omitempty" toml:"IPPrefixLen,omitempty"`
195MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty" toml:"MacAddress,omitempty"`
196Gateway string `json:"Gateway,omitempty" yaml:"Gateway,omitempty" toml:"Gateway,omitempty"`
197Bridge string `json:"Bridge,omitempty" yaml:"Bridge,omitempty" toml:"Bridge,omitempty"`
198PortMapping map[string]PortMapping `json:"PortMapping,omitempty" yaml:"PortMapping,omitempty" toml:"PortMapping,omitempty"`
199Ports map[Port][]PortBinding `json:"Ports,omitempty" yaml:"Ports,omitempty" toml:"Ports,omitempty"`
200NetworkID string `json:"NetworkID,omitempty" yaml:"NetworkID,omitempty" toml:"NetworkID,omitempty"`
201EndpointID string `json:"EndpointID,omitempty" yaml:"EndpointID,omitempty" toml:"EndpointID,omitempty"`
202SandboxKey string `json:"SandboxKey,omitempty" yaml:"SandboxKey,omitempty" toml:"SandboxKey,omitempty"`
203GlobalIPv6Address string `json:"GlobalIPv6Address,omitempty" yaml:"GlobalIPv6Address,omitempty" toml:"GlobalIPv6Address,omitempty"`
204GlobalIPv6PrefixLen int `json:"GlobalIPv6PrefixLen,omitempty" yaml:"GlobalIPv6PrefixLen,omitempty" toml:"GlobalIPv6PrefixLen,omitempty"`
205IPv6Gateway string `json:"IPv6Gateway,omitempty" yaml:"IPv6Gateway,omitempty" toml:"IPv6Gateway,omitempty"`
206LinkLocalIPv6Address string `json:"LinkLocalIPv6Address,omitempty" yaml:"LinkLocalIPv6Address,omitempty" toml:"LinkLocalIPv6Address,omitempty"`
207LinkLocalIPv6PrefixLen int `json:"LinkLocalIPv6PrefixLen,omitempty" yaml:"LinkLocalIPv6PrefixLen,omitempty" toml:"LinkLocalIPv6PrefixLen,omitempty"`
208SecondaryIPAddresses []string `json:"SecondaryIPAddresses,omitempty" yaml:"SecondaryIPAddresses,omitempty" toml:"SecondaryIPAddresses,omitempty"`
209SecondaryIPv6Addresses []string `json:"SecondaryIPv6Addresses,omitempty" yaml:"SecondaryIPv6Addresses,omitempty" toml:"SecondaryIPv6Addresses,omitempty"`
210}
211
212// PortMappingAPI translates the port mappings as contained in NetworkSettings
213// into the format in which they would appear when returned by the API
214func (settings *NetworkSettings) PortMappingAPI() []APIPort {
215var mapping []APIPort
216for port, bindings := range settings.Ports {
217p, _ := parsePort(port.Port())
218if len(bindings) == 0 {
219mapping = append(mapping, APIPort{
220PrivatePort: int64(p),
221Type: port.Proto(),
222})
223continue
224}
225for _, binding := range bindings {
226p, _ := parsePort(port.Port())
227h, _ := parsePort(binding.HostPort)
228mapping = append(mapping, APIPort{
229PrivatePort: int64(p),
230PublicPort: int64(h),
231Type: port.Proto(),
232IP: binding.HostIP,
233})
234}
235}
236return mapping
237}
238
239func parsePort(rawPort string) (int, error) {
240port, err := strconv.ParseUint(rawPort, 10, 16)
241if err != nil {
242return 0, err
243}
244return int(port), nil
245}
246
247// Config is the list of configuration options used when creating a container.
248// Config does not contain the options that are specific to starting a container on a
249// given host. Those are contained in HostConfig
250type Config struct {
251Hostname string `json:"Hostname,omitempty" yaml:"Hostname,omitempty" toml:"Hostname,omitempty"`
252Domainname string `json:"Domainname,omitempty" yaml:"Domainname,omitempty" toml:"Domainname,omitempty"`
253User string `json:"User,omitempty" yaml:"User,omitempty" toml:"User,omitempty"`
254Memory int64 `json:"Memory,omitempty" yaml:"Memory,omitempty" toml:"Memory,omitempty"`
255MemorySwap int64 `json:"MemorySwap,omitempty" yaml:"MemorySwap,omitempty" toml:"MemorySwap,omitempty"`
256MemoryReservation int64 `json:"MemoryReservation,omitempty" yaml:"MemoryReservation,omitempty" toml:"MemoryReservation,omitempty"`
257KernelMemory int64 `json:"KernelMemory,omitempty" yaml:"KernelMemory,omitempty" toml:"KernelMemory,omitempty"`
258CPUShares int64 `json:"CpuShares,omitempty" yaml:"CpuShares,omitempty" toml:"CpuShares,omitempty"`
259CPUSet string `json:"Cpuset,omitempty" yaml:"Cpuset,omitempty" toml:"Cpuset,omitempty"`
260PortSpecs []string `json:"PortSpecs,omitempty" yaml:"PortSpecs,omitempty" toml:"PortSpecs,omitempty"`
261ExposedPorts map[Port]struct{} `json:"ExposedPorts,omitempty" yaml:"ExposedPorts,omitempty" toml:"ExposedPorts,omitempty"`
262PublishService string `json:"PublishService,omitempty" yaml:"PublishService,omitempty" toml:"PublishService,omitempty"`
263StopSignal string `json:"StopSignal,omitempty" yaml:"StopSignal,omitempty" toml:"StopSignal,omitempty"`
264StopTimeout int `json:"StopTimeout,omitempty" yaml:"StopTimeout,omitempty" toml:"StopTimeout,omitempty"`
265Env []string `json:"Env,omitempty" yaml:"Env,omitempty" toml:"Env,omitempty"`
266Cmd []string `json:"Cmd" yaml:"Cmd" toml:"Cmd"`
267Shell []string `json:"Shell,omitempty" yaml:"Shell,omitempty" toml:"Shell,omitempty"`
268Healthcheck *HealthConfig `json:"Healthcheck,omitempty" yaml:"Healthcheck,omitempty" toml:"Healthcheck,omitempty"`
269DNS []string `json:"Dns,omitempty" yaml:"Dns,omitempty" toml:"Dns,omitempty"` // For Docker API v1.9 and below only
270Image string `json:"Image,omitempty" yaml:"Image,omitempty" toml:"Image,omitempty"`
271Volumes map[string]struct{} `json:"Volumes,omitempty" yaml:"Volumes,omitempty" toml:"Volumes,omitempty"`
272VolumeDriver string `json:"VolumeDriver,omitempty" yaml:"VolumeDriver,omitempty" toml:"VolumeDriver,omitempty"`
273WorkingDir string `json:"WorkingDir,omitempty" yaml:"WorkingDir,omitempty" toml:"WorkingDir,omitempty"`
274MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty" toml:"MacAddress,omitempty"`
275Entrypoint []string `json:"Entrypoint" yaml:"Entrypoint" toml:"Entrypoint"`
276SecurityOpts []string `json:"SecurityOpts,omitempty" yaml:"SecurityOpts,omitempty" toml:"SecurityOpts,omitempty"`
277OnBuild []string `json:"OnBuild,omitempty" yaml:"OnBuild,omitempty" toml:"OnBuild,omitempty"`
278Mounts []Mount `json:"Mounts,omitempty" yaml:"Mounts,omitempty" toml:"Mounts,omitempty"`
279Labels map[string]string `json:"Labels,omitempty" yaml:"Labels,omitempty" toml:"Labels,omitempty"`
280AttachStdin bool `json:"AttachStdin,omitempty" yaml:"AttachStdin,omitempty" toml:"AttachStdin,omitempty"`
281AttachStdout bool `json:"AttachStdout,omitempty" yaml:"AttachStdout,omitempty" toml:"AttachStdout,omitempty"`
282AttachStderr bool `json:"AttachStderr,omitempty" yaml:"AttachStderr,omitempty" toml:"AttachStderr,omitempty"`
283ArgsEscaped bool `json:"ArgsEscaped,omitempty" yaml:"ArgsEscaped,omitempty" toml:"ArgsEscaped,omitempty"`
284Tty bool `json:"Tty,omitempty" yaml:"Tty,omitempty" toml:"Tty,omitempty"`
285OpenStdin bool `json:"OpenStdin,omitempty" yaml:"OpenStdin,omitempty" toml:"OpenStdin,omitempty"`
286StdinOnce bool `json:"StdinOnce,omitempty" yaml:"StdinOnce,omitempty" toml:"StdinOnce,omitempty"`
287NetworkDisabled bool `json:"NetworkDisabled,omitempty" yaml:"NetworkDisabled,omitempty" toml:"NetworkDisabled,omitempty"`
288
289// This is no longer used and has been kept here for backward
290// compatibility, please use HostConfig.VolumesFrom.
291VolumesFrom string `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty" toml:"VolumesFrom,omitempty"`
292}
293
294// HostMount represents a mount point in the container in HostConfig.
295//
296// It has been added in the version 1.25 of the Docker API
297type HostMount struct {
298Target string `json:"Target,omitempty" yaml:"Target,omitempty" toml:"Target,omitempty"`
299Source string `json:"Source,omitempty" yaml:"Source,omitempty" toml:"Source,omitempty"`
300Type string `json:"Type,omitempty" yaml:"Type,omitempty" toml:"Type,omitempty"`
301ReadOnly bool `json:"ReadOnly,omitempty" yaml:"ReadOnly,omitempty" toml:"ReadOnly,omitempty"`
302BindOptions *BindOptions `json:"BindOptions,omitempty" yaml:"BindOptions,omitempty" toml:"BindOptions,omitempty"`
303VolumeOptions *VolumeOptions `json:"VolumeOptions,omitempty" yaml:"VolumeOptions,omitempty" toml:"VolumeOptions,omitempty"`
304TempfsOptions *TempfsOptions `json:"TmpfsOptions,omitempty" yaml:"TmpfsOptions,omitempty" toml:"TmpfsOptions,omitempty"`
305}
306
307// BindOptions contains optional configuration for the bind type
308type BindOptions struct {
309Propagation string `json:"Propagation,omitempty" yaml:"Propagation,omitempty" toml:"Propagation,omitempty"`
310}
311
312// VolumeOptions contains optional configuration for the volume type
313type VolumeOptions struct {
314NoCopy bool `json:"NoCopy,omitempty" yaml:"NoCopy,omitempty" toml:"NoCopy,omitempty"`
315Labels map[string]string `json:"Labels,omitempty" yaml:"Labels,omitempty" toml:"Labels,omitempty"`
316DriverConfig VolumeDriverConfig `json:"DriverConfig,omitempty" yaml:"DriverConfig,omitempty" toml:"DriverConfig,omitempty"`
317}
318
319// TempfsOptions contains optional configuration for the tempfs type
320type TempfsOptions struct {
321SizeBytes int64 `json:"SizeBytes,omitempty" yaml:"SizeBytes,omitempty" toml:"SizeBytes,omitempty"`
322Mode int `json:"Mode,omitempty" yaml:"Mode,omitempty" toml:"Mode,omitempty"`
323}
324
325// VolumeDriverConfig holds a map of volume driver specific options
326type VolumeDriverConfig struct {
327Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
328Options map[string]string `json:"Options,omitempty" yaml:"Options,omitempty" toml:"Options,omitempty"`
329}
330
331// Mount represents a mount point in the container.
332//
333// It has been added in the version 1.20 of the Docker API, available since
334// Docker 1.8.
335type Mount struct {
336Name string
337Source string
338Destination string
339Driver string
340Mode string
341RW bool
342}
343
344// LogConfig defines the log driver type and the configuration for it.
345type LogConfig struct {
346Type string `json:"Type,omitempty" yaml:"Type,omitempty" toml:"Type,omitempty"`
347Config map[string]string `json:"Config,omitempty" yaml:"Config,omitempty" toml:"Config,omitempty"`
348}
349
350// ULimit defines system-wide resource limitations This can help a lot in
351// system administration, e.g. when a user starts too many processes and
352// therefore makes the system unresponsive for other users.
353type ULimit struct {
354Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
355Soft int64 `json:"Soft,omitempty" yaml:"Soft,omitempty" toml:"Soft,omitempty"`
356Hard int64 `json:"Hard,omitempty" yaml:"Hard,omitempty" toml:"Hard,omitempty"`
357}
358
359// SwarmNode containers information about which Swarm node the container is on.
360type SwarmNode struct {
361ID string `json:"ID,omitempty" yaml:"ID,omitempty" toml:"ID,omitempty"`
362IP string `json:"IP,omitempty" yaml:"IP,omitempty" toml:"IP,omitempty"`
363Addr string `json:"Addr,omitempty" yaml:"Addr,omitempty" toml:"Addr,omitempty"`
364Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
365CPUs int64 `json:"CPUs,omitempty" yaml:"CPUs,omitempty" toml:"CPUs,omitempty"`
366Memory int64 `json:"Memory,omitempty" yaml:"Memory,omitempty" toml:"Memory,omitempty"`
367Labels map[string]string `json:"Labels,omitempty" yaml:"Labels,omitempty" toml:"Labels,omitempty"`
368}
369
370// GraphDriver contains information about the GraphDriver used by the
371// container.
372type GraphDriver struct {
373Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
374Data map[string]string `json:"Data,omitempty" yaml:"Data,omitempty" toml:"Data,omitempty"`
375}
376
377// HealthConfig holds configuration settings for the HEALTHCHECK feature
378//
379// It has been added in the version 1.24 of the Docker API, available since
380// Docker 1.12.
381type HealthConfig struct {
382// Test is the test to perform to check that the container is healthy.
383// An empty slice means to inherit the default.
384// The options are:
385// {} : inherit healthcheck
386// {"NONE"} : disable healthcheck
387// {"CMD", args...} : exec arguments directly
388// {"CMD-SHELL", command} : run command with system's default shell
389Test []string `json:"Test,omitempty" yaml:"Test,omitempty" toml:"Test,omitempty"`
390
391// Zero means to inherit. Durations are expressed as integer nanoseconds.
392Interval time.Duration `json:"Interval,omitempty" yaml:"Interval,omitempty" toml:"Interval,omitempty"` // Interval is the time to wait between checks.
393Timeout time.Duration `json:"Timeout,omitempty" yaml:"Timeout,omitempty" toml:"Timeout,omitempty"` // Timeout is the time to wait before considering the check to have hung.
394StartPeriod time.Duration `json:"StartPeriod,omitempty" yaml:"StartPeriod,omitempty" toml:"StartPeriod,omitempty"` // The start period for the container to initialize before the retries starts to count down.
395
396// Retries is the number of consecutive failures needed to consider a container as unhealthy.
397// Zero means inherit.
398Retries int `json:"Retries,omitempty" yaml:"Retries,omitempty" toml:"Retries,omitempty"`
399}
400
401// Container is the type encompasing everything about a container - its config,
402// hostconfig, etc.
403type Container struct {
404ID string `json:"Id" yaml:"Id" toml:"Id"`
405
406Created time.Time `json:"Created,omitempty" yaml:"Created,omitempty" toml:"Created,omitempty"`
407
408Path string `json:"Path,omitempty" yaml:"Path,omitempty" toml:"Path,omitempty"`
409Args []string `json:"Args,omitempty" yaml:"Args,omitempty" toml:"Args,omitempty"`
410
411Config *Config `json:"Config,omitempty" yaml:"Config,omitempty" toml:"Config,omitempty"`
412State State `json:"State,omitempty" yaml:"State,omitempty" toml:"State,omitempty"`
413Image string `json:"Image,omitempty" yaml:"Image,omitempty" toml:"Image,omitempty"`
414
415Node *SwarmNode `json:"Node,omitempty" yaml:"Node,omitempty" toml:"Node,omitempty"`
416
417NetworkSettings *NetworkSettings `json:"NetworkSettings,omitempty" yaml:"NetworkSettings,omitempty" toml:"NetworkSettings,omitempty"`
418
419SysInitPath string `json:"SysInitPath,omitempty" yaml:"SysInitPath,omitempty" toml:"SysInitPath,omitempty"`
420ResolvConfPath string `json:"ResolvConfPath,omitempty" yaml:"ResolvConfPath,omitempty" toml:"ResolvConfPath,omitempty"`
421HostnamePath string `json:"HostnamePath,omitempty" yaml:"HostnamePath,omitempty" toml:"HostnamePath,omitempty"`
422HostsPath string `json:"HostsPath,omitempty" yaml:"HostsPath,omitempty" toml:"HostsPath,omitempty"`
423LogPath string `json:"LogPath,omitempty" yaml:"LogPath,omitempty" toml:"LogPath,omitempty"`
424Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
425Driver string `json:"Driver,omitempty" yaml:"Driver,omitempty" toml:"Driver,omitempty"`
426Mounts []Mount `json:"Mounts,omitempty" yaml:"Mounts,omitempty" toml:"Mounts,omitempty"`
427
428Volumes map[string]string `json:"Volumes,omitempty" yaml:"Volumes,omitempty" toml:"Volumes,omitempty"`
429VolumesRW map[string]bool `json:"VolumesRW,omitempty" yaml:"VolumesRW,omitempty" toml:"VolumesRW,omitempty"`
430HostConfig *HostConfig `json:"HostConfig,omitempty" yaml:"HostConfig,omitempty" toml:"HostConfig,omitempty"`
431ExecIDs []string `json:"ExecIDs,omitempty" yaml:"ExecIDs,omitempty" toml:"ExecIDs,omitempty"`
432GraphDriver *GraphDriver `json:"GraphDriver,omitempty" yaml:"GraphDriver,omitempty" toml:"GraphDriver,omitempty"`
433
434RestartCount int `json:"RestartCount,omitempty" yaml:"RestartCount,omitempty" toml:"RestartCount,omitempty"`
435
436AppArmorProfile string `json:"AppArmorProfile,omitempty" yaml:"AppArmorProfile,omitempty" toml:"AppArmorProfile,omitempty"`
437
438MountLabel string `json:"MountLabel,omitempty" yaml:"MountLabel,omitempty" toml:"MountLabel,omitempty"`
439ProcessLabel string `json:"ProcessLabel,omitempty" yaml:"ProcessLabel,omitempty" toml:"ProcessLabel,omitempty"`
440Platform string `json:"Platform,omitempty" yaml:"Platform,omitempty" toml:"Platform,omitempty"`
441SizeRw int64 `json:"SizeRw,omitempty" yaml:"SizeRw,omitempty" toml:"SizeRw,omitempty"`
442SizeRootFs int64 `json:"SizeRootFs,omitempty" yaml:"SizeRootFs,omitempty" toml:"SizeRootFs,omitempty"`
443}
444
445// KeyValuePair is a type for generic key/value pairs as used in the Lxc
446// configuration
447type KeyValuePair struct {
448Key string `json:"Key,omitempty" yaml:"Key,omitempty" toml:"Key,omitempty"`
449Value string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
450}
451
452// Device represents a device mapping between the Docker host and the
453// container.
454type Device struct {
455PathOnHost string `json:"PathOnHost,omitempty" yaml:"PathOnHost,omitempty" toml:"PathOnHost,omitempty"`
456PathInContainer string `json:"PathInContainer,omitempty" yaml:"PathInContainer,omitempty" toml:"PathInContainer,omitempty"`
457CgroupPermissions string `json:"CgroupPermissions,omitempty" yaml:"CgroupPermissions,omitempty" toml:"CgroupPermissions,omitempty"`
458}
459
460// DeviceRequest represents a request for device that's sent to device drivers.
461type DeviceRequest struct {
462Driver string `json:"Driver,omitempty" yaml:"Driver,omitempty" toml:"Driver,omitempty"`
463Count int `json:"Count,omitempty" yaml:"Count,omitempty" toml:"Count,omitempty"`
464DeviceIDs []string `json:"DeviceIDs,omitempty" yaml:"DeviceIDs,omitempty" toml:"DeviceIDs,omitempty"`
465Capabilities [][]string `json:"Capabilities,omitempty" yaml:"Capabilities,omitempty" toml:"Capabilities,omitempty"`
466Options map[string]string `json:"Options,omitempty" yaml:"Options,omitempty" toml:"Options,omitempty"`
467}
468
469// BlockWeight represents a relative device weight for an individual device inside
470// of a container
471type BlockWeight struct {
472Path string `json:"Path,omitempty"`
473Weight string `json:"Weight,omitempty"`
474}
475
476// BlockLimit represents a read/write limit in IOPS or Bandwidth for a device
477// inside of a container
478type BlockLimit struct {
479Path string `json:"Path,omitempty"`
480Rate int64 `json:"Rate,omitempty"`
481}
482
483// HostConfig contains the container options related to starting a container on
484// a given host
485type HostConfig struct {
486Binds []string `json:"Binds,omitempty" yaml:"Binds,omitempty" toml:"Binds,omitempty"`
487CapAdd []string `json:"CapAdd,omitempty" yaml:"CapAdd,omitempty" toml:"CapAdd,omitempty"`
488CapDrop []string `json:"CapDrop,omitempty" yaml:"CapDrop,omitempty" toml:"CapDrop,omitempty"`
489Capabilities []string `json:"Capabilities,omitempty" yaml:"Capabilities,omitempty" toml:"Capabilities,omitempty"` // Mutually exclusive w.r.t. CapAdd and CapDrop API v1.40
490GroupAdd []string `json:"GroupAdd,omitempty" yaml:"GroupAdd,omitempty" toml:"GroupAdd,omitempty"`
491ContainerIDFile string `json:"ContainerIDFile,omitempty" yaml:"ContainerIDFile,omitempty" toml:"ContainerIDFile,omitempty"`
492LxcConf []KeyValuePair `json:"LxcConf,omitempty" yaml:"LxcConf,omitempty" toml:"LxcConf,omitempty"`
493PortBindings map[Port][]PortBinding `json:"PortBindings,omitempty" yaml:"PortBindings,omitempty" toml:"PortBindings,omitempty"`
494Links []string `json:"Links,omitempty" yaml:"Links,omitempty" toml:"Links,omitempty"`
495DNS []string `json:"Dns,omitempty" yaml:"Dns,omitempty" toml:"Dns,omitempty"` // For Docker API v1.10 and above only
496DNSOptions []string `json:"DnsOptions,omitempty" yaml:"DnsOptions,omitempty" toml:"DnsOptions,omitempty"`
497DNSSearch []string `json:"DnsSearch,omitempty" yaml:"DnsSearch,omitempty" toml:"DnsSearch,omitempty"`
498ExtraHosts []string `json:"ExtraHosts,omitempty" yaml:"ExtraHosts,omitempty" toml:"ExtraHosts,omitempty"`
499VolumesFrom []string `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty" toml:"VolumesFrom,omitempty"`
500UsernsMode string `json:"UsernsMode,omitempty" yaml:"UsernsMode,omitempty" toml:"UsernsMode,omitempty"`
501NetworkMode string `json:"NetworkMode,omitempty" yaml:"NetworkMode,omitempty" toml:"NetworkMode,omitempty"`
502IpcMode string `json:"IpcMode,omitempty" yaml:"IpcMode,omitempty" toml:"IpcMode,omitempty"`
503Isolation string `json:"Isolation,omitempty" yaml:"Isolation,omitempty" toml:"Isolation,omitempty"` // Windows only
504ConsoleSize [2]int `json:"ConsoleSize,omitempty" yaml:"ConsoleSize,omitempty" toml:"ConsoleSize,omitempty"` // Windows only height x width
505PidMode string `json:"PidMode,omitempty" yaml:"PidMode,omitempty" toml:"PidMode,omitempty"`
506UTSMode string `json:"UTSMode,omitempty" yaml:"UTSMode,omitempty" toml:"UTSMode,omitempty"`
507RestartPolicy RestartPolicy `json:"RestartPolicy,omitempty" yaml:"RestartPolicy,omitempty" toml:"RestartPolicy,omitempty"`
508Devices []Device `json:"Devices,omitempty" yaml:"Devices,omitempty" toml:"Devices,omitempty"`
509DeviceCgroupRules []string `json:"DeviceCgroupRules,omitempty" yaml:"DeviceCgroupRules,omitempty" toml:"DeviceCgroupRules,omitempty"`
510DeviceRequests []DeviceRequest `json:"DeviceRequests,omitempty" yaml:"DeviceRequests,omitempty" toml:"DeviceRequests,omitempty"`
511LogConfig LogConfig `json:"LogConfig,omitempty" yaml:"LogConfig,omitempty" toml:"LogConfig,omitempty"`
512SecurityOpt []string `json:"SecurityOpt,omitempty" yaml:"SecurityOpt,omitempty" toml:"SecurityOpt,omitempty"`
513CgroupnsMode string `json:"CgroupnsMode,omitempty" yaml:"CgroupnsMode,omitempty" toml:"CgroupnsMode,omitempty"` // v1.40+
514Cgroup string `json:"Cgroup,omitempty" yaml:"Cgroup,omitempty" toml:"Cgroup,omitempty"`
515CgroupParent string `json:"CgroupParent,omitempty" yaml:"CgroupParent,omitempty" toml:"CgroupParent,omitempty"`
516Memory int64 `json:"Memory,omitempty" yaml:"Memory,omitempty" toml:"Memory,omitempty"`
517MemoryReservation int64 `json:"MemoryReservation,omitempty" yaml:"MemoryReservation,omitempty" toml:"MemoryReservation,omitempty"`
518KernelMemory int64 `json:"KernelMemory,omitempty" yaml:"KernelMemory,omitempty" toml:"KernelMemory,omitempty"`
519MemorySwap int64 `json:"MemorySwap,omitempty" yaml:"MemorySwap,omitempty" toml:"MemorySwap,omitempty"`
520CPUShares int64 `json:"CpuShares,omitempty" yaml:"CpuShares,omitempty" toml:"CpuShares,omitempty"`
521CPUSet string `json:"Cpuset,omitempty" yaml:"Cpuset,omitempty" toml:"Cpuset,omitempty"`
522CPUSetCPUs string `json:"CpusetCpus,omitempty" yaml:"CpusetCpus,omitempty" toml:"CpusetCpus,omitempty"`
523CPUSetMEMs string `json:"CpusetMems,omitempty" yaml:"CpusetMems,omitempty" toml:"CpusetMems,omitempty"`
524CPUQuota int64 `json:"CpuQuota,omitempty" yaml:"CpuQuota,omitempty" toml:"CpuQuota,omitempty"`
525CPUPeriod int64 `json:"CpuPeriod,omitempty" yaml:"CpuPeriod,omitempty" toml:"CpuPeriod,omitempty"`
526CPURealtimePeriod int64 `json:"CpuRealtimePeriod,omitempty" yaml:"CpuRealtimePeriod,omitempty" toml:"CpuRealtimePeriod,omitempty"`
527CPURealtimeRuntime int64 `json:"CpuRealtimeRuntime,omitempty" yaml:"CpuRealtimeRuntime,omitempty" toml:"CpuRealtimeRuntime,omitempty"`
528NanoCPUs int64 `json:"NanoCpus,omitempty" yaml:"NanoCpus,omitempty" toml:"NanoCpus,omitempty"`
529BlkioWeight int64 `json:"BlkioWeight,omitempty" yaml:"BlkioWeight,omitempty" toml:"BlkioWeight,omitempty"`
530BlkioWeightDevice []BlockWeight `json:"BlkioWeightDevice,omitempty" yaml:"BlkioWeightDevice,omitempty" toml:"BlkioWeightDevice,omitempty"`
531BlkioDeviceReadBps []BlockLimit `json:"BlkioDeviceReadBps,omitempty" yaml:"BlkioDeviceReadBps,omitempty" toml:"BlkioDeviceReadBps,omitempty"`
532BlkioDeviceReadIOps []BlockLimit `json:"BlkioDeviceReadIOps,omitempty" yaml:"BlkioDeviceReadIOps,omitempty" toml:"BlkioDeviceReadIOps,omitempty"`
533BlkioDeviceWriteBps []BlockLimit `json:"BlkioDeviceWriteBps,omitempty" yaml:"BlkioDeviceWriteBps,omitempty" toml:"BlkioDeviceWriteBps,omitempty"`
534BlkioDeviceWriteIOps []BlockLimit `json:"BlkioDeviceWriteIOps,omitempty" yaml:"BlkioDeviceWriteIOps,omitempty" toml:"BlkioDeviceWriteIOps,omitempty"`
535Ulimits []ULimit `json:"Ulimits,omitempty" yaml:"Ulimits,omitempty" toml:"Ulimits,omitempty"`
536VolumeDriver string `json:"VolumeDriver,omitempty" yaml:"VolumeDriver,omitempty" toml:"VolumeDriver,omitempty"`
537OomScoreAdj int `json:"OomScoreAdj,omitempty" yaml:"OomScoreAdj,omitempty" toml:"OomScoreAdj,omitempty"`
538MemorySwappiness *int64 `json:"MemorySwappiness,omitempty" yaml:"MemorySwappiness,omitempty" toml:"MemorySwappiness,omitempty"`
539PidsLimit *int64 `json:"PidsLimit,omitempty" yaml:"PidsLimit,omitempty" toml:"PidsLimit,omitempty"`
540OOMKillDisable *bool `json:"OomKillDisable,omitempty" yaml:"OomKillDisable,omitempty" toml:"OomKillDisable,omitempty"`
541ShmSize int64 `json:"ShmSize,omitempty" yaml:"ShmSize,omitempty" toml:"ShmSize,omitempty"`
542Tmpfs map[string]string `json:"Tmpfs,omitempty" yaml:"Tmpfs,omitempty" toml:"Tmpfs,omitempty"`
543StorageOpt map[string]string `json:"StorageOpt,omitempty" yaml:"StorageOpt,omitempty" toml:"StorageOpt,omitempty"`
544Sysctls map[string]string `json:"Sysctls,omitempty" yaml:"Sysctls,omitempty" toml:"Sysctls,omitempty"`
545CPUCount int64 `json:"CpuCount,omitempty" yaml:"CpuCount,omitempty"`
546CPUPercent int64 `json:"CpuPercent,omitempty" yaml:"CpuPercent,omitempty"`
547IOMaximumBandwidth int64 `json:"IOMaximumBandwidth,omitempty" yaml:"IOMaximumBandwidth,omitempty"`
548IOMaximumIOps int64 `json:"IOMaximumIOps,omitempty" yaml:"IOMaximumIOps,omitempty"`
549Mounts []HostMount `json:"Mounts,omitempty" yaml:"Mounts,omitempty" toml:"Mounts,omitempty"`
550MaskedPaths []string `json:"MaskedPaths,omitempty" yaml:"MaskedPaths,omitempty" toml:"MaskedPaths,omitempty"`
551ReadonlyPaths []string `json:"ReadonlyPaths,omitempty" yaml:"ReadonlyPaths,omitempty" toml:"ReadonlyPaths,omitempty"`
552Runtime string `json:"Runtime,omitempty" yaml:"Runtime,omitempty" toml:"Runtime,omitempty"`
553Init bool `json:",omitempty" yaml:",omitempty"`
554Privileged bool `json:"Privileged,omitempty" yaml:"Privileged,omitempty" toml:"Privileged,omitempty"`
555PublishAllPorts bool `json:"PublishAllPorts,omitempty" yaml:"PublishAllPorts,omitempty" toml:"PublishAllPorts,omitempty"`
556ReadonlyRootfs bool `json:"ReadonlyRootfs,omitempty" yaml:"ReadonlyRootfs,omitempty" toml:"ReadonlyRootfs,omitempty"`
557AutoRemove bool `json:"AutoRemove,omitempty" yaml:"AutoRemove,omitempty" toml:"AutoRemove,omitempty"`
558}
559
560// NetworkingConfig represents the container's networking configuration for each of its interfaces
561// Carries the networking configs specified in the `docker run` and `docker network connect` commands
562type NetworkingConfig struct {
563EndpointsConfig map[string]*EndpointConfig `json:"EndpointsConfig" yaml:"EndpointsConfig" toml:"EndpointsConfig"` // Endpoint configs for each connecting network
564}
565
566// NoSuchContainer is the error returned when a given container does not exist.
567type NoSuchContainer struct {
568ID string
569Err error
570}
571
572func (err *NoSuchContainer) Error() string {
573if err.Err != nil {
574return err.Err.Error()
575}
576return "No such container: " + err.ID
577}
578
579// ContainerAlreadyRunning is the error returned when a given container is
580// already running.
581type ContainerAlreadyRunning struct {
582ID string
583}
584
585func (err *ContainerAlreadyRunning) Error() string {
586return "Container already running: " + err.ID
587}
588
589// ContainerNotRunning is the error returned when a given container is not
590// running.
591type ContainerNotRunning struct {
592ID string
593}
594
595func (err *ContainerNotRunning) Error() string {
596return "Container not running: " + err.ID
597}
598