2024-02-24 20:21:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Script Name: docker-installer.v3.sh
|
2024-06-12 12:11:44 +00:00
|
|
|
# Beschreibung: Docker & Docker-Compose Installer für Ubuntu 22.04 Jammy und Ubuntu 24.04
|
2024-02-24 20:21:41 +00:00
|
|
|
# Aufruf: bash ./docker-installer.v3.sh
|
|
|
|
# Autor: Patrick Asmus
|
2024-03-31 11:54:35 +00:00
|
|
|
# Web: https://www.techniverse.net
|
2024-04-08 18:37:30 +00:00
|
|
|
# Git-Reposit.: https://git.techniverse.net/scriptos/linux-docker-installer
|
2024-09-29 11:17:58 +00:00
|
|
|
# Version: 3.4.3
|
|
|
|
# Datum: 29.09.2024
|
|
|
|
# Modifikation: docker bin directory moved
|
2024-02-24 20:21:41 +00:00
|
|
|
#####################################################
|
|
|
|
|
2024-06-12 12:58:55 +00:00
|
|
|
# Variablen:
|
|
|
|
COMPOSEVERSION="v2.27.1"
|
|
|
|
|
2024-04-08 18:37:30 +00:00
|
|
|
# Betriebssystem und Version prüfen
|
|
|
|
OS=$(lsb_release -is)
|
|
|
|
VERSION=$(lsb_release -rs)
|
|
|
|
|
2024-06-12 12:11:44 +00:00
|
|
|
if [ "$OS" != "Ubuntu" ] || { [ "$VERSION" != "22.04" ] && [ "$VERSION" != "24.04" ]; }; then
|
|
|
|
echo "Dieses Script unterstützt nur Ubuntu 22.04 und Ubuntu 24.04. Installation abgebrochen."
|
2024-04-08 18:37:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-24 20:21:41 +00:00
|
|
|
# Variablen
|
|
|
|
USER="root"
|
2024-09-29 11:17:58 +00:00
|
|
|
DOCKER_ROOT_DIR="/var/docker-bin"
|
2024-03-10 13:24:23 +00:00
|
|
|
COMPOSE_DIR="/docker-compose"
|
2024-02-24 20:21:41 +00:00
|
|
|
|
|
|
|
# Docker installieren
|
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
|
2024-06-12 12:11:44 +00:00
|
|
|
|
|
|
|
if [ "$VERSION" == "22.04" ]; then
|
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
|
|
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
elif [ "$VERSION" == "24.04" ]; then
|
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
fi
|
|
|
|
|
2024-02-24 20:21:41 +00:00
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y docker-ce docker-ce-cli containerd.io
|
2024-06-12 12:11:44 +00:00
|
|
|
|
2024-02-24 20:21:41 +00:00
|
|
|
sudo usermod -aG docker $USER
|
|
|
|
|
2024-04-08 18:37:30 +00:00
|
|
|
# Docker-Root-Verzeichnis ändern & Compose Verzeichnis erstellen
|
2024-02-24 20:21:41 +00:00
|
|
|
sudo systemctl stop docker
|
|
|
|
sudo mkdir -p $DOCKER_ROOT_DIR
|
2024-06-12 12:11:44 +00:00
|
|
|
echo "{\"data-root\": \"$DOCKER_ROOT_DIR\"}" | sudo tee /etc/docker/daemon.json > /dev/null
|
|
|
|
cp /var/lib/docker/* $DOCKER_ROOT_DIR -r
|
2024-02-24 20:21:41 +00:00
|
|
|
rm -R /var/lib/docker
|
|
|
|
sudo systemctl start docker
|
|
|
|
|
2024-06-12 12:11:44 +00:00
|
|
|
mkdir -p $COMPOSE_DIR
|
2024-02-24 20:21:41 +00:00
|
|
|
|
2024-06-12 12:11:44 +00:00
|
|
|
# Docker-compose installieren (gleicher Prozess für beide Versionen)
|
2024-02-24 20:21:41 +00:00
|
|
|
sudo apt install -y curl
|
2024-06-12 12:58:55 +00:00
|
|
|
sudo curl -L "https://github.com/docker/compose/releases/download/$COMPOSEVERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
2024-02-24 20:21:41 +00:00
|
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
|
|
|
|
|
|
|
# Optional: Plugin für Oh my ZSH aktivieren
|
|
|
|
echo "OhMyZSH Plugin für Docker hinzufügen"
|
|
|
|
sudo sed -i 's/plugins=(git)/plugins=(git docker)/g' /root/.zshrc
|
|
|
|
|
|
|
|
# Überprüfen der Installation
|
|
|
|
docker --version
|
|
|
|
docker-compose --version
|
|
|
|
|
2024-06-12 12:11:44 +00:00
|
|
|
exit 0
|