Documentation
¶
Index ¶
- Constants
- func ClientOpts(c client.HijackDialer) []bkclient.ClientOpt
- func ComposeProjectLabel(labels map[string]string) string
- func ComposeServiceLabel(labels map[string]string) string
- func ConsumeJSONMessageStream(reader io.Reader, lineHandler func([]byte) error) error
- func ContainerNameFromNames(names []string) string
- func FilterContainersUsingVolume(containers []container.Summary, volumeName string) []string
- func GetContainersUsingVolume(ctx context.Context, dockerClient *client.Client, volumeName string) ([]string, error)
- func GetCurrentContainerID() (string, error)
- func GetHostPathForContainerPath(ctx context.Context, dockerCli *client.Client, containerPath string) (string, error)
- func GetVolumeUsageData(ctx context.Context, dockerClient *client.Client) ([]volume.Volume, error)
- func InvalidateVolumeUsageCache()
- func IsDefaultNetwork(name string) bool
- func IsDockerContainer() bool
- func MountForDestination(mounts []containertypes.MountPoint, destination string, target string) *mounttypes.Mount
- func ReadAllLogs(ctx context.Context, logs io.ReadCloser, logsChan chan<- string) error
- func StreamContainerLogs(ctx context.Context, logs io.ReadCloser, logsChan chan<- string, follow bool, ...) error
- func StreamMultiplexedLogs(ctx context.Context, logs io.Reader, logsChan chan<- string) error
- type CgroupLimits
Constants ¶
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 ¶
ComposeProjectLabel returns the trimmed Docker Compose project name from a container's labels, or "" when unset.
func ComposeServiceLabel ¶
ComposeServiceLabel returns the trimmed Docker Compose service name from a container's labels, or "" when unset.
func ConsumeJSONMessageStream ¶
ConsumeJSONMessageStream drains a Docker JSON message stream and returns any daemon-reported error. Optional lineHandler receives each raw line before parsing.
func ContainerNameFromNames ¶
ContainerNameFromNames returns Docker's first container name without the leading slash Docker stores in container summaries.
func FilterContainersUsingVolume ¶
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 ¶
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 InvalidateVolumeUsageCache ¶
func InvalidateVolumeUsageCache()
func IsDefaultNetwork ¶
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 ¶
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.
Types ¶
type CgroupLimits ¶
type CgroupLimits struct {
MemoryLimit int64
MemoryUsage int64
CPUQuota int64
CPUPeriod int64
CPUCount int
}
func DetectCgroupLimits ¶
func DetectCgroupLimits() (*CgroupLimits, error)