docker-aio/install.sh

92 lines
2.8 KiB
Bash
Raw Normal View History

2023-04-17 20:29:01 +02:00
#!/bin/bash
# This script installs Docker and Docker Compose on a Linux system.
# It detects the Linux distribution (Ubuntu, Debian, CentOS, Alpine, or openSUSE) and installs the packages accordingly.
# The script also asks the user if they want to install Docker Compose.
# Function to install Docker on Ubuntu and Debian
install_docker_deb() {
sudo apt-get update
2023-04-17 20:45:33 +02:00
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/${1}/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/${1} $(lsb_release -cs) stable"
2023-04-17 20:29:01 +02:00
sudo apt-get update
2023-04-17 20:40:17 +02:00
sudo apt-get install -y docker-ce docker-ce-cli containerd.io || { echo "Unable to install 'docker-ce'. Exiting."; exit 1; }
2023-04-17 20:29:01 +02:00
}
# Function to install Docker on CentOS
install_docker_centos() {
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
2023-04-17 20:40:17 +02:00
sudo yum install -y docker-ce docker-ce-cli containerd.io
2023-04-17 20:29:01 +02:00
sudo systemctl enable docker
sudo systemctl start docker
}
# Function to install Docker on Alpine
install_docker_alpine() {
sudo apk add --no-cache docker
sudo rc-update add docker boot
sudo service docker start
}
# Function to install Docker on openSUSE
install_docker_opensuse() {
sudo zypper install -y docker
sudo systemctl enable docker
sudo systemctl start docker
}
# Function to install Docker Compose
install_docker_compose() {
2023-04-17 20:45:33 +02:00
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2023-04-17 20:29:01 +02:00
sudo chmod +x /usr/local/bin/docker-compose
}
echo "Detecting Linux distribution..."
DISTRO=""
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
DISTRO=$DISTRIB_ID
else
echo "Unsupported Linux distribution."
exit 1
fi
echo "Detected Linux distribution: $DISTRO"
case "$DISTRO" in
"ubuntu" | "debian")
echo "Installing Docker on $DISTRO..."
install_docker_deb $DISTRO
;;
"centos")
echo "Installing Docker on CentOS..."
install_docker_centos
;;
"alpine")
echo "Installing Docker on Alpine..."
install_docker_alpine
;;
2023-04-17 20:43:09 +02:00
"opensuse" | "opensuse-leap" | "opensuse-tumbleweed")
echo "Installing Docker on openSUSE..."
2023-04-17 20:45:33 +02:00
install_docker_opensuse
;;
*)
echo "Unsupported Linux distribution."
exit 1
;;
esac
echo "Docker installed successfully."
# Prompt user for Docker Compose installation
while true; do
read -p "Do you want to install Docker Compose? (y/n): " yn
case $yn in
[Yy]* )
echo "Installing Docker Compose..."
install_docker_compose