containerutils

package
v0.0.0-...-9e2e732 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: Unlicense Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ALPHANUMERICS_REGEX = `^[a-zA-Z0-9_-]+$`
)

Variables

View Source
var (
	VALID_RESTART_POLICY = regexp.MustCompile(`^(always|no|unless-stopped|on-failure:\d+)$`)
	VALID_VOLUME_NAME    = VALID_CONTAINER_NAME
	VALID_CONTAINER_NAME = regexp.MustCompile(ALPHANUMERICS_REGEX)
	VALID_NETWORK_NAME   = VALID_CONTAINER_NAME
)

Functions

func CheckContainerExists

func CheckContainerExists(container_name string) (bool, error)

CheckContainerExists checks if a container exists by its name

func CheckContainerRunsWithImage

func CheckContainerRunsWithImage(container_name, image string) (bool, error)

CheckContainerRunsWithImage checks if a container is running with a specific image

func CheckVolumeExists

func CheckVolumeExists(volume_name string) bool

CheckVolumeExists checks if a volume exists by its name

func CopyContainerResource

func CopyContainerResource(container_name string, source string, destination string) error

func CreateContainer

func CreateContainer(container_name string, image string, labels map[string]string, volumes map[string]string, ports map[int]int, env map[string]string, restart_policy string, cap_add []string, cmd []string) error

func CreateContainerNetwork

func CreateContainerNetwork(network_name, driver string) error

CreateContainerNetwork creates a network if it doesn't exist

func CreateVolume

func CreateVolume(volume_name string, driver string, labels map[string]string) error

CreateVolume creates a volume with a given name, driver, and labels

func FetchContainerLogs

func FetchContainerLogs(container_name string) (string, error)

FetchContainerLogs returns the logs of a container by its name returns the entire log as a string

func FetchContainerStatus

func FetchContainerStatus(container_name string) (string, error)

FetchContainerStatus returns the status of a container by its name

func GetContainerEngine

func GetContainerEngine() string

func GetContainerEnvVariable

func GetContainerEnvVariable(container_name string, variable string) (string, error)

func GetContainersNetwork

func GetContainersNetwork() string

func ImageAlreadyExists

func ImageAlreadyExists(image_name string) (bool, error)

func PullImage

func PullImage(image_name string) error

func RemoveContainer

func RemoveContainer(container_name string, delete_volumes bool) error

RemoveContainer deletes a container by its name, and optionally deletes its volumes

func RemoveVolume

func RemoveVolume(volume_name string, force bool) error

RemoveVolume deletes a volume by its name WARNING: force is set to true to remove the volume even if it is in use

func ResumeContainer

func ResumeContainer(container_name string) error

ResumeContainer resumes a container by its name

func RunContainerCommand

func RunContainerCommand(container_name string, command ...string) error

func RunContainerCommandWithOutput

func RunContainerCommandWithOutput(containerName string, command ...string) ([]byte, error)

func SetContainerEngine

func SetContainerEngine(op string) error

========== Container engine ==========

func SetContainersNetwork

func SetContainersNetwork(network string) error

========== Container network ==========

func StopContainer

func StopContainer(container_name string) error

func WaitForContainerReadiness

func WaitForContainerReadiness(container_name string, retry_interval int, max_retries int) error

WaitForContainerReadiness waits for a container to be in a running state, with a configurable retry interval and maximum number of retries

Types

This section is empty.

Jump to

Keyboard shortcuts

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