docker

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComposeProjectLabelKey = "com.docker.compose.project"
	ComposeServiceLabelKey = "com.docker.compose.service"
)

Docker Compose attaches these labels to every container it manages. They identify the owning project and the service within that project.

Variables

This section is empty.

Functions

func ClientOpts

func ClientOpts(c client.HijackDialer) []bkclient.ClientOpt

ClientOpts returns a list of buildkit client options which allows the caller to create a buildkit client which will connect to the buildkit API provided by the daemon. These options can be passed to bkclient.New.

Example:

bkclient.New(ctx, "", ClientOpts(c)...)

func ComposeProjectLabel

func ComposeProjectLabel(labels map[string]string) string

ComposeProjectLabel returns the trimmed Docker Compose project name from a container's labels, or "" when unset.

func ComposeServiceLabel

func ComposeServiceLabel(labels map[string]string) string

ComposeServiceLabel returns the trimmed Docker Compose service name from a container's labels, or "" when unset.

func ConsumeJSONMessageStream

func ConsumeJSONMessageStream(reader io.Reader, lineHandler func([]byte) error) error

ConsumeJSONMessageStream drains a Docker JSON message stream and returns any daemon-reported error. Optional lineHandler receives each raw line before parsing.

func ContainerNameFromNames

func ContainerNameFromNames(names []string) string

ContainerNameFromNames returns Docker's first container name without the leading slash Docker stores in container summaries.

func FilterContainersUsingVolume

func FilterContainersUsingVolume(containers []container.Summary, volumeName string) []string

FilterContainersUsingVolume returns the IDs of containers in the provided slice that mount the named volume. Use this when checking many volumes in a row — list containers once and reuse the slice.

func GetContainersUsingVolume

func GetContainersUsingVolume(ctx context.Context, dockerClient *client.Client, volumeName string) ([]string, error)

GetContainersUsingVolume lists all containers and returns IDs that mount the named volume. For batch checks (multiple volumes), prefer listing containers once via dockerClient.ContainerList and calling FilterContainersUsingVolume per volume.

func GetCurrentContainerID

func GetCurrentContainerID() (string, error)

GetCurrentContainerID detects the current container ID using multiple detection methods It tries cgroup, mountinfo, and hostname in that order

func GetHostPathForContainerPath

func GetHostPathForContainerPath(ctx context.Context, dockerCli *client.Client, containerPath string) (string, error)

GetHostPathForContainerPath attempts to discover the host-side path for a given container path by inspecting the container itself. This is useful for Docker-in-Docker scenarios where the application needs to know host paths for volume mapping.

func GetVolumeUsageData

func GetVolumeUsageData(ctx context.Context, dockerClient *client.Client) ([]volume.Volume, error)

func InvalidateVolumeUsageCache

func InvalidateVolumeUsageCache()

func IsDefaultNetwork

func IsDefaultNetwork(name string) bool

func IsDockerContainer

func IsDockerContainer() bool

IsDockerContainer reports whether the current process is running inside a Docker container (as opposed to an LXC container, a VM, or bare metal).

The distinction matters for System Overview stats: in Docker the cgroup limits (--cpus / --memory) are artificial constraints set by the operator and should NOT be used as the host resource totals shown in the dashboard. In LXC, by contrast, the cgroup limits represent the real hardware budget assigned to the container — gopsutil reads the host's /proc values which are higher, so the cgroup limits must be applied to show correct figures.

Detection: Docker always creates /.dockerenv inside every container it starts. LXC does not. We fall back to a /proc/self/cgroup pattern check as a secondary signal.

func MountForDestination

func MountForDestination(mounts []containertypes.MountPoint, destination string, target string) *mounttypes.Mount

MountForDestination returns a Mount suitable for container creation that mirrors an existing container mount at the given destination.

It currently supports bind and named volume mounts. If target is empty, destination is used as the target.

func ReadAllLogs

func ReadAllLogs(ctx context.Context, logs io.ReadCloser, logsChan chan<- string) error

ReadAllLogs reads a non-follow Docker multiplexed log stream and sends non-empty stdout/stderr lines to logsChan.

func StreamContainerLogs

func StreamContainerLogs(ctx context.Context, logs io.ReadCloser, logsChan chan<- string, follow bool, isTTY bool) error

StreamContainerLogs streams Docker container logs, handling TTY raw streams and non-TTY multiplexed stdout/stderr streams.

func StreamMultiplexedLogs

func StreamMultiplexedLogs(ctx context.Context, logs io.Reader, logsChan chan<- string) error

StreamMultiplexedLogs demultiplexes a Docker stdout/stderr log stream and sends non-empty lines to logsChan.

Types

type CgroupLimits

type CgroupLimits struct {
	MemoryLimit int64
	MemoryUsage int64
	CPUQuota    int64
	CPUPeriod   int64
	CPUCount    int
}

func DetectCgroupLimits

func DetectCgroupLimits() (*CgroupLimits, error)

Jump to

Keyboard shortcuts

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