Update scripts/fix_docker.sh

This commit is contained in:
2025-07-31 17:12:35 +00:00
parent 5052e0da70
commit 5a8aa4bb73
+23 -23
View File
@@ -3,20 +3,20 @@ set -e
# Ensure script is run as root # Ensure script is run as root
if [[ $EUID -ne 0 ]]; then if [[ $EUID -ne 0 ]]; then
echo "This script must be run with sudo or as root." echo "This script must be run with sudo or as root."
exit 1 exit 1
fi fi
# 1) Remove any old Docker and Docker Compose packages # 1) Remove any old Docker and Docker Compose packages
echo "Removing old Docker packages..." echo "Removing old Docker packages..."
set +e set +e
apt-get remove -y \ apt-get remove -y \
docker docker-engine docker.io docker-ce docker-ce-cli \ docker docker-engine docker.io docker-ce docker-ce-cli \
containerd runc \ containerd runc \
docker-compose docker-compose
set -e set -e
# Note: The above command may fail if Docker is not installed, which is fine. # Note: The above command may fail if Docker is not installed, which is fine.
# The script will continue to install the latest version. # The script will continue to install the latest version.
# 2) Update package index # 2) Update package index
echo "Updating APT package index..." echo "Updating APT package index..."
@@ -25,31 +25,31 @@ apt-get update -y
# 3) Install prerequisite packages # 3) Install prerequisite packages
echo "Installing prerequisites..." echo "Installing prerequisites..."
apt-get install -y \ apt-get install -y \
ca-certificates \ ca-certificates \
curl \ curl \
gnupg \ gnupg \
lsb-release lsb-release
# 4) Add Dockers official GPG key # 4) Add Dockers official GPG key
echo "Adding Dockers GPG key..." echo "Adding Dockers GPG key..."
install -m 0755 -d /etc/apt/keyrings install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \ curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg chmod a+r /etc/apt/keyrings/docker.gpg
# ubuntu or debian? # ubuntu or debian?
KIND=$(lsb_release -is | tr '[:upper:]' '[:lower:]') KIND=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
if [[ "$KIND" != "ubuntu" && "$KIND" != "debian" ]]; then if [[ "$KIND" != "ubuntu" && "$KIND" != "debian" ]]; then
echo "This script is intended for Ubuntu or Debian systems only." echo "This script is intended for Ubuntu or Debian systems only."
exit 1 exit 1
fi fi
# 5) Set up the Docker APT repository # 5) Set up the Docker APT repository
echo \ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/$KIND \ https://download.docker.com/linux/$KIND \
$(lsb_release -cs) stable" \ $(lsb_release -cs) stable" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null | tee /etc/apt/sources.list.d/docker.list > /dev/null
# 6) Update the package index again # 6) Update the package index again
echo "Updating APT package index with Docker repo..." echo "Updating APT package index with Docker repo..."
@@ -58,18 +58,18 @@ apt-get update -y
# 7) Install the latest Docker Engine, CLI, containerd, and Compose plugin # 7) Install the latest Docker Engine, CLI, containerd, and Compose plugin
echo "Installing Docker Engine, CLI, containerd, and Docker Compose plugin..." echo "Installing Docker Engine, CLI, containerd, and Docker Compose plugin..."
apt-get install -y \ apt-get install -y \
docker-ce \ docker-ce \
docker-ce-cli \ docker-ce-cli \
containerd.io \ containerd.io \
docker-compose-plugin docker-compose-plugin
# 8) (Optional) Install legacy docker-compose binary # 8) (Optional) Install legacy docker-compose binary
# Uncomment below if you still need the standalone 'docker-compose' command # Uncomment below if you still need the standalone 'docker-compose' command
# echo "Installing legacy docker-compose binary..." # echo "Installing legacy docker-compose binary..."
# COMPOSE_LATEST=$(curl -s https://api.github.com/repos/docker/compose/releases/latest \ # COMPOSE_LATEST=$(curl -s https://api.github.com/repos/docker/compose/releases/latest \
# | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') # | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_LATEST}/docker-compose-$(uname -s)-$(uname -m)" \ # curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_LATEST}/docker-compose-$(uname -s)-$(uname -m)" \
# -o /usr/local/bin/docker-compose # -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose # chmod +x /usr/local/bin/docker-compose
# 9) Add current user to the 'docker' group (so you can run docker without sudo) # 9) Add current user to the 'docker' group (so you can run docker without sudo)