add ensure_docker for addons

This commit is contained in:
MickLesk
2026-08-03 09:25:54 +02:00
parent 34717720d4
commit 0cea54711b
2 changed files with 49 additions and 16 deletions
+47
View File
@@ -4630,6 +4630,53 @@ _docker_is_noninteractive() {
[[ "${DOCKER_NONINTERACTIVE:-}" == "1" || "${DOCKER_NONINTERACTIVE:-}" == "true" || "${DOCKER_NONINTERACTIVE:-}" == "TRUE" ]] || [[ ! -t 0 ]]
}
# ------------------------------------------------------------------------------
# ensure_docker()
#
# - Docker precondition for addon scripts that ship a compose stack
# - Reuses an existing installation, otherwise offers to install Docker
# (Debian/Ubuntu via setup_docker, Alpine via apk)
# - Aborts when the user declines or Compose is unavailable afterwards
# ------------------------------------------------------------------------------
ensure_docker() {
if command -v docker &>/dev/null; then
msg_ok "Docker $(docker --version | cut -d' ' -f3 | tr -d ',') is available"
if docker compose version &>/dev/null; then
msg_ok "Docker Compose is available"
return 0
fi
msg_error "Docker Compose plugin is not available. Please install it."
exit 237
fi
msg_warn "Docker is not installed."
echo -n "${TAB:- }Install Docker now? (y/N): "
local install_docker_prompt
read -r install_docker_prompt
if [[ ! "${install_docker_prompt,,}" =~ ^(y|yes)$ ]]; then
msg_error "Docker is required for ${APP:-this script}. Exiting."
exit 254
fi
if is_alpine; then
msg_info "Installing Docker"
$STD apk add --no-cache docker docker-cli-compose
$STD rc-update add docker default
$STD rc-service docker start
msg_ok "Installed Docker"
else
setup_docker || {
msg_error "Docker installation failed."
exit 237
}
fi
if ! command -v docker &>/dev/null || ! docker compose version &>/dev/null; then
msg_error "Docker or the Compose plugin is still unavailable after installation."
exit 237
fi
}
setup_docker() {
local docker_installed=false
local portainer_installed=false
+2 -16
View File
@@ -67,26 +67,11 @@ function update() {
exit
}
# ==============================================================================
# CHECK DOCKER
# ==============================================================================
function check_docker() {
if ! command -v docker &>/dev/null; then
msg_error "Docker is not installed. This script requires an existing Docker LXC. Exiting."
exit 10
fi
if ! docker compose version &>/dev/null; then
msg_error "Docker Compose plugin is not available. Please install it before running this script. Exiting."
exit 10
fi
msg_ok "Docker $(docker --version | cut -d' ' -f3 | tr -d ',') and Docker Compose are available"
}
# ==============================================================================
# INSTALL
# ==============================================================================
function install() {
check_docker
ensure_docker
msg_info "Creating install directory"
mkdir -p "$INSTALL_PATH"
@@ -163,6 +148,7 @@ if [[ "${type:-}" == "update" ]]; then
fi
header_info
confirm_not_pve_host
get_lxc_ip
# Check if already installed