First Commit
This commit is contained in:
53
README.md
Normal file
53
README.md
Normal file
@@ -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.
|
||||
78
install-docker.sh
Normal file
78
install-docker.sh
Normal file
@@ -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."
|
||||
✓
|
||||
Reference in New Issue
Block a user