Add docker-install.sh

This commit is contained in:
2026-08-19 00:02:53 +00:00
commit 4457fce36d

61
docker-install.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -euo pipefail
echo "==> Removing conflicting Docker/container packages..."
sudo apt remove -y \
docker.io \
docker-compose \
docker-compose-v2 \
docker-doc \
docker-buildx \
podman-docker \
containerd \
runc
echo "==> Updating package lists..."
sudo apt update
echo "==> Installing prerequisites..."
sudo apt install -y ca-certificates curl
echo "==> Installing Docker's official GPG key..."
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL \
https://download.docker.com/linux/ubuntu/gpg \
-o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "==> Adding Docker's official repository..."
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
echo "==> Updating package lists with Docker repository..."
sudo apt update
echo "==> Installing Docker Engine and Compose..."
sudo apt install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
echo "==> Enabling and starting Docker..."
sudo systemctl enable --now docker
echo "==> Testing Docker installation..."
sudo docker run --rm hello-world
echo
echo "========================================"
echo " Docker installation completed!"
echo "========================================"
docker --version
docker compose version