docker

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientOpts added in v1.17.2

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 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 GetContainersUsingVolume

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

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 added in v1.18.0

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.

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