commit f0eea88aae809fad0419c8737e1385f1a95530ee Author: Your Name Date: Wed Dec 31 20:26:58 2025 -0800 First Commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..c4f0071 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# install-docker.sh β€” Docker installer script + +## Purpose +- Installs Docker Engine, CLI, containerd and Compose plugin across common Linux distributions (Ubuntu/Debian, CentOS/RHEL, Fedora, Alpine, Arch). + +## Requirements +- A Linux system with one of the supported distributions. +- `sudo` privileges for the user running the script. +- Internet access to download packages from Docker repositories. + +## Usage +1. Make the script executable (if not already): + +```bash +chmod +x install-docker.sh +``` + +2. Run the script as your normal user (you will be prompted for sudo): + +```bash +./install-docker.sh +``` + +The script detects your OS via `/etc/os-release` and runs the appropriate package commands. + +## Post-install steps +- The script enables and starts the Docker service via `systemctl`. +- It also adds the current user to the `docker` group. You may need to log out and log back in (or run `newgrp docker`) to use Docker without `sudo`. + +## Notes & Troubleshooting +- Unsupported OS: the script exits with an error if the distribution is not recognized. +- On systems without `systemd` (or where `systemctl` is unavailable), service start/enable will failβ€”start Docker manually as appropriate for your init system. +- If package repository GPG fetch or keyring operations fail, verify network access and that `curl`/`gnupg` are present. +- The script assumes typical package managers: `apt`, `yum`, `dnf`, `apk`, or `pacman`. + +## Example +```bash +# Run installer (prompts for sudo) +./install-docker.sh + +# Verify Docker +docker --version +sudo systemctl status docker +``` + +## Security +- The script adds official Docker package repositories and installs upstream packages. Review the commands if you have custom security requirements. + +## Contributing / Changes +- To adapt the script for additional distributions or custom mirrors, add/modify the `case` branches that handle installation for each `OS`. + +## License +- No license included. If you want this README or script under a specific license, add a LICENSE file. diff --git a/install-docker.sh b/install-docker.sh new file mode 100644 index 0000000..0ed19e4 --- /dev/null +++ b/install-docker.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +set -e + +echo "🧠 Detecting OS..." + +# Detect OS +if [ -f /etc/os-release ]; then + . /etc/os-release + OS=$ID + VERSION_ID=$VERSION_ID +else + echo "❌ Cannot determine OS. /etc/os-release not found." + exit 1 +fi + +echo "πŸ“¦ Installing Docker for: $OS $VERSION_ID" + +# Install Docker based on detected OS +case "$OS" in + ubuntu|debian) + sudo apt-get update + sudo apt-get install -y ca-certificates curl gnupg lsb-release + + sudo install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/$OS/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + sudo chmod a+r /etc/apt/keyrings/docker.gpg + + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$OS \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + + sudo apt-get update + sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + ;; + + centos|rhel) + sudo yum install -y yum-utils + sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + ;; + + fedora) + sudo dnf -y install dnf-plugins-core + sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo + sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + ;; + + alpine) + sudo apk update + sudo apk add docker docker-cli docker-compose + ;; + + arch) + sudo pacman -Sy --noconfirm docker docker-compose + ;; + + *) + echo "❌ Unsupported OS: $OS" + exit 1 + ;; +esac + +echo "βœ… Docker installed successfully." + +# Start and enable Docker +echo "πŸš€ Starting Docker..." +sudo systemctl enable docker +sudo systemctl start docker + +# Add current user to docker group +if ! groups $USER | grep -q docker; then + echo "πŸ‘€ Adding $USER to docker group (you may need to log out and in again)..." + sudo usermod -aG docker $USER +fi + +echo "βœ… Done! You can now run Docker as your user." + βœ“ \ No newline at end of file