docker

package
v0.4.98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

credit: https://github.com/containrrr/watchtower

Index

Constants

View Source
const ChallengeHeader = "WWW-Authenticate"

ChallengeHeader is the HTTP Header containing challenge instructions

View Source
const ContentDigestHeader = "Docker-Content-Digest"

ContentDigestHeader is the key for the key-value pair containing the digest header

View Source
const NETWORKNAME = "oasis"

Variables

View Source
var Cache *cache.Cache

Functions

func BuildManifestURL

func BuildManifestURL(imageName string) (string, error)

BuildManifestURL from raw image data

func CPUPercent added in v0.4.37

func CPUPercent(s *container.StatsResponse) float64

CPUPercent is how busy a container has been BETWEEN two samples, which is why a single sample cannot answer it: CPU usage is a counter that only goes up, so a lone reading says how much CPU the container has used since it started, not how much it is using now.

Docker ships the previous sample inside the current one, so the arithmetic is the same as `docker stats`: the container's own delta over the machine's, times the number of CPUs it could have been running on. A container pinned at 100% of two cores reads 200, like the CLI, rather than 100.

Zero when the deltas make no sense -- the first frame of a stream carries an empty previous sample, and a container that stopped between samples goes backwards.

func CloneContainer

func CloneContainer(ctx context.Context, id string, newName string) (string, error)

func CompareDigest

func CompareDigest(imageName string, repoDigests []string) (bool, error)

CompareDigest ...

func Container

func Container(ctx context.Context, id string) (*types.ContainerJSON, error)

func ContainsDigest

func ContainsDigest(repoDigests []string, digest string) bool

ContainsDigest reports whether a local image's RepoDigests include one digest. RepoDigests read `repo@sha256:...`; an entry without the `@` is not one and is skipped rather than indexed into.

func ConvertToHostname

func ConvertToHostname(url string) (string, string, error)

ConvertToHostname strips a url from everything but the hostname part

func CredentialsStore

func CredentialsStore(configFile configfile.ConfigFile) credentials.Store

CredentialsStore returns a new credentials store based on the settings provided in the configuration file.

func CurrentArchitecture

func CurrentArchitecture() (string, error)

func EncodeAuth

func EncodeAuth(authConfig types.AuthConfig) (string, error)

EncodeAuth Base64 encode an AuthConfig struct for transmission over HTTP

func EncodedAuth

func EncodedAuth(ref string) (string, error)

EncodedAuth returns an encoded auth config for the given registry loaded from environment variables or docker config as available in that order

func EncodedConfigAuth

func EncodedConfigAuth(ref string) (string, error)

EncodedConfigAuth returns an encoded auth config for the given registry loaded from the docker config Returns an empty string if credentials cannot be found for the referenced server

The config is $DOCKER_CONFIG when set. Otherwise it is the one `docker login` writes (~/.docker/config.json, the home of the user this process runs as when it has no HOME), then the root of the file system, where a container that had the config mounted found it.

func EncodedEnvAuth

func EncodedEnvAuth(ref string) (string, error)

EncodedEnvAuth returns an encoded auth config for the given registry loaded from environment variables Returns an error if authentication environment variables have not been set

func ExtractImageAndTag

func ExtractImageAndTag(imageName string) (string, string)

ExtractImageAndTag splits a reference into the image and its tag.

The colon that separates a tag is the last one AFTER the last slash. A registry carries a port before the first slash -- `registry:5000/img:2.0` -- and splitting on the first colon returned `registry` and `5000/img:2.0`. That string is not a version, so the update check treated every such app as unorderable and offered it whatever the catalogue held, in either direction.

A reference pinned by digest has no tag at all, and comes back whole with an empty tag rather than split at the digest's own colon.

func GetArchitectures

func GetArchitectures(imageName string, noCache bool) ([]string, error)

func GetAuthURL

func GetAuthURL(challenge string, img string) (*url.URL, error)

GetAuthURL from the instructions in the challenge

func GetBearerHeader

func GetBearerHeader(challenge string, img string, registryAuth string) (string, error)

GetBearerHeader tries to fetch a bearer token from the registry based on the challenge instructions

func GetChallenge

func GetChallenge(imageName string) (string, error)

GetChallenge fetches a challenge for the registry hosting the provided image

func GetChallengeRequest

func GetChallengeRequest(URL url.URL) (*http.Request, error)

GetChallengeRequest creates a request for getting challenge instructions

func GetChallengeURL

func GetChallengeURL(img string) (url.URL, error)

GetChallengeURL creates a URL object based on the image info

func GetDigest

func GetDigest(url string, token string) (string, error)

GetDigest from registry using a HEAD request to prevent rate limiting

func GetDir

func GetDir(id, envName string) string

func GetManifest

func GetManifest(ctx context.Context, imageName string) (interface{}, string, error)

func GetPullOptions

func GetPullOptions(imageName string) (image.PullOptions, error)

GetPullOptions creates a struct with all options needed for pulling images from a registry

func GetScopeFromImageName

func GetScopeFromImageName(img, svc string) string

GetScopeFromImageName normalizes an image name for use as scope during auth and head requests

func GetToken

func GetToken(challenge string, registryAuth string, imageName string) (string, error)

func HasNewImage

func HasNewImage(ctx context.Context, imageName string, currentImageID string) (bool, string, error)

func Image

func Image(ctx context.Context, imageName string) (*types.ImageInspect, error)

func ImageName

func ImageName(containerInfo *types.ContainerJSON) string

func IsDaemonRunning

func IsDaemonRunning() bool

func MemoryUsage added in v0.4.37

func MemoryUsage(s *container.StatsResponse) (used uint64, limit uint64)

MemoryUsage is what the container actually holds, and its ceiling.

Docker's raw `usage` counts the page cache, which makes a container that has merely read a large file look like it is holding it. Both the CLI and every dashboard worth trusting subtract that: `inactive_file` under cgroup v2, and `total_inactive_file` under v1. Neither key is present on Windows, where the raw value is already the working set.

The limit is the host's whole memory when the container declares none, which is Docker's own answer and is what makes the percentage meaningful.

func NormalizeRegistry

func NormalizeRegistry(registry string) (string, error)

NormalizeRegistry makes sure variations of DockerHubs registry

func ParseServerAddress

func ParseServerAddress(ref string) (string, error)

ParseServerAddress extracts the server part from a container image ref

func PullImage

func PullImage(ctx context.Context, imageName string, handleOut func(io.ReadCloser)) error

func RegistryDigest

func RegistryDigest(imageName string) (string, error)

RegistryDigest is the digest the registry publishes for an image reference right now.

Exposed on its own because a caller holding several local digests -- one per running container of a service, say -- has to compare each of them against the registry, and a yes/no about one set of digests cannot say which of them matched.

func RemoveContainer

func RemoveContainer(ctx context.Context, id string) error

func RenameContainer

func RenameContainer(ctx context.Context, id string, name string) error

func RestartContainer added in v0.4.37

func RestartContainer(ctx context.Context, id string) error

RestartContainer restarts a container, and leaves it running whether or not it was before. Docker's own restart is one call: stop-then-start from here would race anything that reads the container in between, and would have to reinvent the stop timeout the daemon already applies.

func SampleContainerStats added in v0.4.37

func SampleContainerStats(ctx context.Context, cli *client.Client, id string) (*container.StatsResponse, error)

SampleContainerStats reads a container's usage.

It takes TWO frames off the stream rather than asking for one, because one is not enough: the one-shot endpoint returns an empty previous sample, so CPU cannot be computed from it at all. The daemon emits roughly once a second, so this call lasts about that long and the caller's context is what bounds it.

func StartContainer

func StartContainer(ctx context.Context, id string) error

func StopContainer

func StopContainer(ctx context.Context, id string) error

func TransformAuth

func TransformAuth(registryAuth string) string

TransformAuth from a base64 encoded json object to base64 encoded string

func VolumeMountpoint added in v0.4.37

func VolumeMountpoint(ctx context.Context, cli *client.Client, name string) (string, error)

VolumeMountpoint is where the daemon keeps a named volume on this host.

Asked rather than worked out. The path looks predictable -- /var/lib/docker/volumes/<name>/_data -- right up until the daemon has a data-root of its own, or the volume has a driver that puts it somewhere else entirely. A backup that copies from a path nobody confirmed can find an empty folder and report success.

An empty answer means the daemon does not know this volume.

func VolumeUsage added in v0.4.38

func VolumeUsage(ctx context.Context, cli *client.Client) (map[string]VolumeSpace, error)

VolumeUsage is how much room each named volume takes and how many containers reference it.

One call for every volume on the host rather than one per volume: the daemon computes this by walking the filesystem, and asking it repeatedly for the same answer is how a panel that lists four volumes takes ten seconds to open.

A driver that cannot measure a volume reports -1 for the size, and a daemon that cannot count references reports -1 for the count. Both are passed through as they are: "not available" is an answer, and turning it into 0 would read as an empty volume nothing uses, which is exactly the thing somebody would then delete.

func WaitContainer

func WaitContainer(ctx context.Context, id string, condition container.WaitCondition) error

Types

type RegistryCredentials

type RegistryCredentials struct {
	Username string
	Password string // usually a token rather than an actual password
}

RegistryCredentials is a credential pair used for basic auth

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
}

type VolumeSpace added in v0.4.38

type VolumeSpace struct {
	// Size in bytes, or -1 when the driver cannot measure it.
	Size int64
	// Containers referencing it, or -1 when the daemon cannot say.
	Containers int64
}

VolumeSpace is what the daemon can say about a volume's size and use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL