Documentation ¶
Overview ¶
Package container contains code related to dealing with docker containers
Index ¶
- func ContainsWatchtowerLabel(labels map[string]string) bool
- func GetRunningContainerID() (cid types.ContainerID, err error)
- type Client
- type ClientOptions
- type Container
- func (c Container) ContainerInfo() *types.ContainerJSON
- func (c Container) Enabled() (bool, bool)
- func (c Container) GetCreateConfig() *dockercontainer.Config
- func (c Container) GetCreateHostConfig() *dockercontainer.HostConfig
- func (c Container) GetLifecyclePostCheckCommand() string
- func (c Container) GetLifecyclePostUpdateCommand() string
- func (c Container) GetLifecyclePreCheckCommand() string
- func (c Container) GetLifecyclePreUpdateCommand() string
- func (c Container) HasImageInfo() bool
- func (c Container) ID() wt.ContainerID
- func (c Container) ImageID() wt.ImageID
- func (c Container) ImageInfo() *types.ImageInspect
- func (c Container) ImageName() string
- func (c *Container) IsLinkedToRestarting() bool
- func (c Container) IsMonitorOnly(params wt.UpdateParams) bool
- func (c Container) IsNoPull(params wt.UpdateParams) bool
- func (c Container) IsRestarting() bool
- func (c Container) IsRunning() bool
- func (c *Container) IsStale() bool
- func (c Container) IsWatchtower() bool
- func (c Container) Links() []string
- func (c Container) Name() string
- func (c Container) PostUpdateTimeout() int
- func (c Container) PreUpdateTimeout() int
- func (c Container) SafeImageID() wt.ImageID
- func (c Container) Scope() (string, bool)
- func (c *Container) SetLinkedToRestarting(value bool)
- func (c *Container) SetStale(value bool)
- func (c Container) StopSignal() string
- func (c Container) ToRestart() bool
- func (c Container) VerifyConfiguration() error
- type WarningStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsWatchtowerLabel ¶
ContainsWatchtowerLabel takes a map of labels and values and tells the consumer whether it contains a valid watchtower instance label
func GetRunningContainerID ¶
func GetRunningContainerID() (cid types.ContainerID, err error)
GetRunningContainerID tries to resolve the current container ID from the current process cgroup information
Types ¶
type Client ¶
type Client interface { ListContainers(t.Filter) ([]t.Container, error) GetContainer(containerID t.ContainerID) (t.Container, error) StopContainer(t.Container, time.Duration) error StartContainer(t.Container) (t.ContainerID, error) RenameContainer(t.Container, string) error IsContainerStale(t.Container, t.UpdateParams) (stale bool, latestImage t.ImageID, err error) ExecuteCommand(containerID t.ContainerID, command string, timeout int) (SkipUpdate bool, err error) RemoveImageByID(t.ImageID) error WarnOnHeadPullFailed(container t.Container) bool }
A Client is the interface through which watchtower interacts with the Docker API.
func NewClient ¶
func NewClient(opts ClientOptions) Client
NewClient returns a new Client instance which can be used to interact with the Docker API. The client reads its configuration from the following environment variables:
- DOCKER_HOST the docker-engine host to send api requests to
- DOCKER_TLS_VERIFY whether to verify tls certificates
- DOCKER_API_VERSION the minimum docker api version to work with
type ClientOptions ¶
type ClientOptions struct { RemoveVolumes bool IncludeStopped bool ReviveStopped bool IncludeRestarting bool WarnOnHeadFailed WarningStrategy }
ClientOptions contains the options for how the docker client wrapper should behave
type Container ¶
type Container struct { LinkedToRestarting bool Stale bool // contains filtered or unexported fields }
Container represents a running Docker container.
func NewContainer ¶
func NewContainer(containerInfo *types.ContainerJSON, imageInfo *types.ImageInspect) *Container
NewContainer returns a new Container instance instantiated with the specified ContainerInfo and ImageInfo structs.
func (Container) ContainerInfo ¶
func (c Container) ContainerInfo() *types.ContainerJSON
ContainerInfo fetches JSON info for the container
func (Container) Enabled ¶
Enabled returns the value of the container enabled label and if the label was set.
func (Container) GetCreateConfig ¶
func (c Container) GetCreateConfig() *dockercontainer.Config
GetCreateConfig returns the container's current Config converted into a format that can be re-submitted to the Docker create API.
Ideally, we'd just be able to take the ContainerConfig from the old container and use it as the starting point for creating the new container; however, the ContainerConfig that comes back from the Inspect call merges the default configuration (the stuff specified in the metadata for the image itself) with the overridden configuration (the stuff that you might specify as part of the "docker run").
In order to avoid unintentionally overriding the defaults in the new image we need to separate the override options from the default options. To do this we have to compare the ContainerConfig for the running container with the ContainerConfig from the image that container was started from. This function returns a ContainerConfig which contains just the options overridden at runtime.
func (Container) GetCreateHostConfig ¶
func (c Container) GetCreateHostConfig() *dockercontainer.HostConfig
GetCreateHostConfig returns the container's current HostConfig with any links re-written so that they can be re-submitted to the Docker create API.
func (Container) GetLifecyclePostCheckCommand ¶
GetLifecyclePostCheckCommand returns the post-check command set in the container metadata or an empty string
func (Container) GetLifecyclePostUpdateCommand ¶
GetLifecyclePostUpdateCommand returns the post-update command set in the container metadata or an empty string
func (Container) GetLifecyclePreCheckCommand ¶
GetLifecyclePreCheckCommand returns the pre-check command set in the container metadata or an empty string
func (Container) GetLifecyclePreUpdateCommand ¶
GetLifecyclePreUpdateCommand returns the pre-update command set in the container metadata or an empty string
func (Container) HasImageInfo ¶
HasImageInfo returns whether image information could be retrieved for the container
func (Container) ImageID ¶
ImageID returns the ID of the Docker image that was used to start the container. May cause nil dereference if imageInfo is not set!
func (Container) ImageInfo ¶
func (c Container) ImageInfo() *types.ImageInspect
ImageInfo fetches the ImageInspect data of the current container
func (Container) ImageName ¶
ImageName returns the name of the Docker image that was used to start the container. If the original image was specified without a particular tag, the "latest" tag is assumed.
func (*Container) IsLinkedToRestarting ¶
IsLinkedToRestarting returns the current value of the LinkedToRestarting field for the container
func (Container) IsMonitorOnly ¶
func (c Container) IsMonitorOnly(params wt.UpdateParams) bool
IsMonitorOnly returns whether the container should only be monitored based on values of the monitor-only label, the monitor-only argument and the label-take-precedence argument.
func (Container) IsNoPull ¶
func (c Container) IsNoPull(params wt.UpdateParams) bool
IsNoPull returns whether the image should be pulled based on values of the no-pull label, the no-pull argument and the label-take-precedence argument.
func (Container) IsRestarting ¶
IsRestarting returns a boolean flag indicating whether or not the current container is restarting. The status is determined by the value of the container's "State.Restarting" property.
func (Container) IsRunning ¶
IsRunning returns a boolean flag indicating whether or not the current container is running. The status is determined by the value of the container's "State.Running" property.
func (Container) IsWatchtower ¶
IsWatchtower returns a boolean flag indicating whether or not the current container is the watchtower container itself. The watchtower container is identified by the presence of the "com.centurylinklabs.watchtower" label in the container metadata.
func (Container) Links ¶
Links returns a list containing the names of all the containers to which this container is linked.
func (Container) PostUpdateTimeout ¶
PostUpdateTimeout checks whether a container has a specific timeout set for how long the post-update command is allowed to run. This value is expressed either as an integer, in minutes, or as 0 which will allow the command/script to run indefinitely. Users should be cautious with the 0 option, as that could result in watchtower waiting forever.
func (Container) PreUpdateTimeout ¶
PreUpdateTimeout checks whether a container has a specific timeout set for how long the pre-update command is allowed to run. This value is expressed either as an integer, in minutes, or as 0 which will allow the command/script to run indefinitely. Users should be cautious with the 0 option, as that could result in watchtower waiting forever.
func (Container) SafeImageID ¶
SafeImageID returns the ID of the Docker image that was used to start the container if available, otherwise returns an empty string
func (*Container) SetLinkedToRestarting ¶
SetLinkedToRestarting sets the LinkedToRestarting field for the container
func (Container) StopSignal ¶
StopSignal returns the custom stop signal (if any) that is encoded in the container's metadata. If the container has not specified a custom stop signal, the empty string "" is returned.
func (Container) ToRestart ¶
ToRestart return whether the container should be restarted, either because is stale or linked to another stale container.
func (Container) VerifyConfiguration ¶
VerifyConfiguration checks the container and image configurations for nil references to make sure that the container can be recreated once deleted
type WarningStrategy ¶
type WarningStrategy string
WarningStrategy is a value determining when to show warnings
const ( // WarnAlways warns whenever the problem occurs WarnAlways WarningStrategy = "always" // WarnNever never warns when the problem occurs WarnNever WarningStrategy = "never" // WarnAuto skips warning when the problem was expected WarnAuto WarningStrategy = "auto" )