41 lines
1.8 KiB
Bash
41 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [ "$(id -u)" != 0 ]; then
|
|
printf '%s\n' 'Run with sudo. This script installs Docker Engine and the Compose plugin.' >&2
|
|
exit 1
|
|
fi
|
|
. /etc/os-release
|
|
if [ "${ID:-}" != ubuntu ] || [ "${VERSION_ID:-}" != 24.04 ]; then
|
|
printf '%s\n' 'This installer targets the confirmed Ubuntu 24.04 server only.' >&2
|
|
exit 1
|
|
fi
|
|
if command -v docker >/dev/null 2>&1; then
|
|
docker version
|
|
docker compose version
|
|
printf '%s\n' 'Docker already installed; existing packages and settings were left untouched.'
|
|
exit 0
|
|
fi
|
|
for package in docker.io docker-compose docker-compose-v2 podman-docker containerd runc; do
|
|
if dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q 'install ok installed'; then
|
|
printf 'Existing package %s found. Stop and review; nothing will be removed.\n' "$package" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
if [ -e /etc/apt/sources.list.d/docker.sources ] || [ -e /etc/apt/sources.list.d/docker.list ]; then
|
|
printf '%s\n' 'Docker APT configuration exists. Review it before continuing.' >&2
|
|
exit 1
|
|
fi
|
|
apt-get update
|
|
apt-get install -y ca-certificates curl python3 openssl
|
|
install -m 0755 -d /etc/apt/keyrings
|
|
curl -fsSL --connect-timeout 10 --max-time 60 https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
|
chmod a+r /etc/apt/keyrings/docker.asc
|
|
printf 'Types: deb\nURIs: https://download.docker.com/linux/ubuntu\nSuites: noble\nComponents: stable\nArchitectures: %s\nSigned-By: /etc/apt/keyrings/docker.asc\n' "$(dpkg --print-architecture)" > /etc/apt/sources.list.d/docker.sources
|
|
apt-get update
|
|
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
systemctl enable --now docker
|
|
docker version
|
|
docker compose version
|
|
printf '%s\n' 'Installed. No firewall rules, Docker address pools, users or existing applications were changed.'
|