Initial commit: Docker setup script with Docker, Docker Compose, and GitHub CLI installation

This commit is contained in:
Alexis Keates 2026-02-01 15:30:57 +00:00
commit 72bcee099d
5 changed files with 597 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Alexis Keates
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

167
README.md Normal file
View File

@ -0,0 +1,167 @@
# Docker Setup Script
A comprehensive bash script to set up Docker, Docker Compose, and GitHub CLI on Ubuntu/Debian systems with proper permissions and user configuration.
## Features
- ✅ System package updates
- ✅ Docker Engine installation (if not present)
- ✅ Docker Compose V2 plugin installation
- ✅ GitHub CLI (gh) installation
- ✅ Docker group configuration with proper permissions
- ✅ `/srv/containers/` directory creation with ACL support
- ✅ User added to docker group for sudo-less operation
- ✅ Comprehensive error handling and status reporting
## Quick Start
### One-Line Installation
```bash
curl -sL https://raw.githubusercontent.com/alexisskeates/docker-setup-script/main/docker-setup.sh | sudo bash
```
### Manual Installation
```bash
# Download the script
curl -sL https://raw.githubusercontent.com/alexisskeates/docker-setup-script/main/docker-setup.sh -o docker-setup.sh
# Make it executable
chmod +x docker-setup.sh
# Run it
sudo ./docker-setup.sh
```
## What It Does
### 1. System Updates
- Updates package lists
- Upgrades existing packages
- Reports number of packages updated
### 2. Docker Installation
- Checks if Docker is installed
- Adds Docker's official GPG key and repository
- Installs Docker Engine, CLI, containerd, and plugins
- Enables Docker service to start on boot
- Verifies Docker daemon is running
### 3. Docker Group Configuration
- Creates docker group if it doesn't exist
- Adds the current user to the docker group
- Sets up proper permissions for group access
### 4. Docker Compose
- Checks for Docker Compose V2 plugin
- Installs if missing
- Verifies installation
### 5. GitHub CLI
- Checks if `gh` is installed
- Adds GitHub CLI repository
- Installs the latest version
- Verifies installation
### 6. Container Directory Setup
- Creates `/srv/containers/` directory
- Sets ownership to `root:docker`
- Applies `770` permissions (rwxrwx---)
- Configures ACL for inherited permissions
- Ensures all docker group members can access
### 7. Verification
- Tests Docker access for the user
- Provides summary of all installed components
- Lists next steps for activation
## Post-Installation
After running the script, you'll need to activate the docker group membership:
### Option 1: Re-login (Recommended)
```bash
# Log out and log back in
exit
```
### Option 2: Activate in Current Session
```bash
# Start a new shell with docker group active
newgrp docker
```
### Verify Installation
```bash
docker --version
docker compose version
docker ps
gh --version
```
## Requirements
- **OS**: Ubuntu 20.04+ or Debian 10+
- **Privileges**: Must be run with `sudo`
- **Network**: Internet connection required for package downloads
## Permissions
The script creates `/srv/containers/` with the following permissions:
```
Owner: root (rwx)
Group: docker (rwx)
Others: --- (no access)
```
This allows all members of the docker group to:
- Create containers in `/srv/containers/`
- Manage docker-compose projects
- Share container configurations
## Troubleshooting
### "Docker access requires logout/login"
This is normal. The docker group membership requires a new login session. Use `newgrp docker` or log out/in.
### "Failed to update package lists"
Check your internet connection and ensure apt sources are configured correctly.
### "Docker daemon is not running"
Try: `sudo systemctl start docker` and check logs with `sudo journalctl -u docker`
## Security Notes
- The script must be run with `sudo` privileges
- All docker group members have full access to `/srv/containers/`
- Docker group membership is equivalent to root access
- Only add trusted users to the docker group
## Directory Structure
After installation, you'll have:
```
/srv/containers/ # Root directory for all containers
├── (your projects) # Docker Compose projects
└── ...
```
## License
MIT License - See LICENSE file for details
## Contributing
Issues and pull requests are welcome! Please feel free to contribute improvements.
## Author
Alexis Keates - [GitHub](https://github.com/alexisskeates)
## Support
If you encounter any issues, please [open an issue](https://github.com/alexisskeates/docker-setup-script/issues) on GitHub.

BIN
docker-setup-script.tar.gz Normal file

Binary file not shown.

409
docker-setup.sh Executable file
View File

@ -0,0 +1,409 @@
#!/bin/bash
################################################################################
# Docker Setup Script
################################################################################
#
# Description:
# Comprehensive automated setup script for Docker development environments.
# This script prepares Ubuntu/Debian systems with all necessary tools for
# containerized application development and deployment.
#
# What this script does:
# 1. System Updates
# - Updates apt package lists
# - Upgrades all installed packages to latest versions
# - Reports number of packages upgraded
#
# 2. Docker Installation (if not present)
# - Adds Docker's official GPG key and repository
# - Installs Docker Engine, CLI, containerd
# - Installs Docker Buildx and Compose plugins
# - Enables Docker service to start on boot
# - Verifies Docker daemon is running
#
# 3. Docker Group Configuration
# - Creates docker group if it doesn't exist
# - Adds the current user to docker group
# - Enables sudo-less Docker commands (after re-login)
# - Sets up proper group permissions
#
# 4. Docker Compose V2
# - Checks for Docker Compose plugin
# - Installs docker-compose-plugin if missing
# - Verifies installation and version
#
# 5. GitHub CLI Installation
# - Adds GitHub CLI official repository
# - Installs latest version of 'gh' command
# - Verifies installation
#
# 6. Container Directory Setup
# - Creates /srv/containers/ directory structure
# - Sets ownership to root:docker
# - Applies 770 permissions (rwxrwx---)
# - Configures ACL for inherited permissions
# - Ensures all docker group members can create/manage containers
#
# 7. Verification & Summary
# - Tests Docker access for current user
# - Displays installation summary
# - Provides next steps for activation
#
# Requirements:
# - Ubuntu 20.04+ or Debian 10+
# - sudo privileges
# - Internet connection
#
# Usage:
# Quick install:
# curl -sL https://raw.githubusercontent.com/alexisskeates/docker-setup-script/main/docker-setup.sh | sudo bash
#
# Manual download and run:
# curl -O https://raw.githubusercontent.com/alexisskeates/docker-setup-script/main/docker-setup.sh
# chmod +x docker-setup.sh
# sudo ./docker-setup.sh
#
# Post-installation:
# After running, you must activate docker group membership:
# Option 1: Log out and log back in (recommended)
# Option 2: Run 'newgrp docker' in current session
#
# Author: Alexis Keates
# Repository: https://github.com/alexisskeates/docker-setup-script
# License: MIT
#
################################################################################
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_section() {
echo -e "${BLUE}[SECTION]${NC} $1"
}
# Check if running with elevated privileges
if [[ $EUID -ne 0 ]]; then
print_error "This script must be run with sudo"
print_error "Usage: curl -sL https://raw.githubusercontent.com/alexisskeates/docker-setup-script/main/docker-setup.sh | sudo bash"
exit 1
fi
# Get the original user who ran sudo
if [[ -n "$SUDO_USER" ]]; then
ORIGINAL_USER="$SUDO_USER"
ORIGINAL_USER_HOME=$(eval echo "~$SUDO_USER")
else
print_error "Could not determine original user. Please run with sudo, not as root directly."
exit 1
fi
print_status "Running as: $(whoami) (original user: $ORIGINAL_USER)"
echo
# ============================================================================
# SECTION 1: System Updates
# ============================================================================
print_section "Checking for system updates..."
print_status "Updating package lists..."
if apt-get update; then
print_status "Package lists updated successfully"
else
print_error "Failed to update package lists"
exit 1
fi
print_status "Checking for upgradeable packages..."
UPGRADABLE=$(apt list --upgradable 2>/dev/null | tail -n +2 | wc -l)
if [[ $UPGRADABLE -gt 0 ]]; then
print_status "Found $UPGRADABLE upgradeable package(s)"
print_status "Upgrading system packages (this may take a few minutes)..."
if DEBIAN_FRONTEND=noninteractive apt-get upgrade -y; then
print_status "System packages upgraded successfully"
else
print_warning "Some packages failed to upgrade, but continuing..."
fi
else
print_status "System is already up to date"
fi
echo
# ============================================================================
# SECTION 2: Docker Installation Check
# ============================================================================
print_section "Verifying Docker installation..."
if ! command -v docker > /dev/null 2>&1; then
print_warning "Docker is not installed. Installing Docker..."
# Install prerequisites
print_status "Installing prerequisites..."
apt-get install -y ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
print_status "Adding Docker GPG key..."
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
# Set up the repository
print_status "Adding Docker repository..."
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update apt and install Docker
print_status "Installing Docker Engine..."
apt-get update
if apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin; then
print_status "Docker installed successfully"
else
print_error "Failed to install Docker"
exit 1
fi
else
print_status "Docker is already installed ($(docker --version))"
fi
# Enable and start Docker service
print_status "Ensuring Docker service is enabled and running..."
systemctl enable docker
systemctl start docker
# Verify Docker daemon is running
if docker ps > /dev/null 2>&1; then
print_status "Docker daemon is running"
else
print_error "Docker daemon is not running properly"
exit 1
fi
echo
# ============================================================================
# SECTION 3: Docker Group Setup
# ============================================================================
print_section "Setting up Docker group and permissions..."
# Check if docker group exists
if ! getent group docker > /dev/null 2>&1; then
print_warning "Docker group does not exist. Creating it..."
if groupadd docker; then
print_status "Docker group created successfully"
else
print_error "Failed to create docker group"
exit 1
fi
else
print_status "Docker group already exists"
fi
# Check if the original user is in the docker group
if ! groups "$ORIGINAL_USER" | grep -q docker; then
print_status "Adding user $ORIGINAL_USER to docker group..."
if usermod -aG docker "$ORIGINAL_USER"; then
print_status "User added to docker group successfully"
print_warning "Note: User $ORIGINAL_USER will need to log out and back in for group changes to take effect"
print_warning "Or run: newgrp docker"
else
print_error "Failed to add user to docker group"
exit 1
fi
else
print_status "User $ORIGINAL_USER is already in docker group"
fi
echo
# ============================================================================
# SECTION 4: Docker Compose Installation
# ============================================================================
print_section "Checking Docker Compose installation..."
# Check if docker compose is available (V2 plugin style)
if docker compose version > /dev/null 2>&1; then
COMPOSE_VERSION=$(docker compose version --short 2>/dev/null || echo "unknown")
print_status "Docker Compose is already installed (version: $COMPOSE_VERSION)"
# Also check for old standalone docker-compose
elif command -v docker-compose > /dev/null 2>&1; then
COMPOSE_VERSION=$(docker-compose version --short 2>/dev/null || echo "unknown")
print_status "Docker Compose (standalone) is installed (version: $COMPOSE_VERSION)"
print_warning "Consider upgrading to Docker Compose V2 (plugin)"
else
print_warning "Docker Compose not found. Installing..."
# Install Docker Compose plugin (V2)
print_status "Installing docker-compose-plugin..."
if apt-get install -y docker-compose-plugin; then
print_status "Docker Compose plugin installed successfully"
# Verify installation
if docker compose version > /dev/null 2>&1; then
COMPOSE_VERSION=$(docker compose version --short 2>/dev/null || echo "unknown")
print_status "Docker Compose version $COMPOSE_VERSION is now available"
else
print_error "Docker Compose installation verification failed"
exit 1
fi
else
print_error "Failed to install Docker Compose plugin"
exit 1
fi
fi
echo
# ============================================================================
# SECTION 5: GitHub CLI Installation
# ============================================================================
print_section "Checking GitHub CLI installation..."
if command -v gh > /dev/null 2>&1; then
GH_VERSION=$(gh --version | head -n1 | awk '{print $3}')
print_status "GitHub CLI is already installed (version: $GH_VERSION)"
else
print_warning "GitHub CLI not found. Installing..."
# Add GitHub CLI repository
print_status "Adding GitHub CLI repository..."
# Install prerequisites
apt-get install -y curl gpg
# Add GPG key
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
# Add repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
# Update and install
print_status "Installing GitHub CLI..."
apt-get update
if apt-get install -y gh; then
GH_VERSION=$(gh --version | head -n1 | awk '{print $3}')
print_status "GitHub CLI version $GH_VERSION installed successfully"
else
print_error "Failed to install GitHub CLI"
exit 1
fi
fi
echo
# ============================================================================
# SECTION 6: Container Directory Setup
# ============================================================================
print_section "Setting up /srv/containers/ directory..."
# Create the directory if it doesn't exist
if [[ ! -d "/srv/containers" ]]; then
print_status "Creating directory /srv/containers/"
if mkdir -p /srv/containers; then
print_status "Directory created successfully"
else
print_error "Failed to create directory"
exit 1
fi
else
print_status "Directory /srv/containers/ already exists"
fi
# Set ownership to root:docker
print_status "Setting ownership to root:docker"
if chown root:docker /srv/containers; then
print_status "Ownership set successfully"
else
print_error "Failed to set ownership"
exit 1
fi
# Set permissions: owner (root) has full access, group (docker) has read/write, others have no access
print_status "Setting permissions (rwxrwx---)"
if chmod 770 /srv/containers; then
print_status "Permissions set successfully"
else
print_error "Failed to set permissions"
exit 1
fi
# Install ACL if needed
if ! command -v setfacl > /dev/null 2>&1; then
print_status "Installing ACL package..."
apt-get install -y acl > /dev/null 2>&1
fi
# Set default ACL for future files and directories
if command -v setfacl > /dev/null 2>&1; then
print_status "Setting default ACL for future contents"
if setfacl -d -m g:docker:rwx /srv/containers && setfacl -m g:docker:rwx /srv/containers; then
print_status "ACL set successfully"
else
print_warning "Failed to set ACL"
fi
else
print_warning "ACL tools not available. Future files may not inherit proper permissions"
fi
echo
# ============================================================================
# SECTION 7: Verification and Summary
# ============================================================================
print_section "Setup Summary"
echo "Directory details:"
ls -lad /srv/containers 2>/dev/null || print_warning "Could not list directory details"
echo
if command -v getfacl > /dev/null 2>&1; then
echo "ACL details:"
getfacl /srv/containers 2>/dev/null || print_warning "Could not display ACL details"
echo
fi
# Test Docker access for original user
print_status "Testing Docker access for $ORIGINAL_USER..."
if sudo -u "$ORIGINAL_USER" docker ps > /dev/null 2>&1; then
print_status "✓ Docker access working (group change already effective)"
else
print_warning "Docker access requires logout/login or 'newgrp docker'"
fi
echo
print_status "✓ System packages updated"
print_status "✓ Docker installed and verified"
print_status "✓ Docker Compose installed and verified"
print_status "✓ GitHub CLI installed and verified"
print_status "✓ Docker group configured"
print_status "✓ User $ORIGINAL_USER added to docker group"
print_status "✓ /srv/containers/ directory created with proper permissions"
echo
# Final instructions
print_section "IMPORTANT: Next Steps"
print_warning "To use Docker without sudo, $ORIGINAL_USER needs the docker group to be active."
print_warning "Since we just added you to the docker group, you need to either:"
echo " 1. Log out and back in to your SSH session, OR"
echo " 2. Run: newgrp docker (in current session)"
echo
print_status "After re-logging or running 'newgrp docker', test with:"
echo " • docker --version"
echo " • docker compose version"
echo " • docker ps"
echo " • gh --version"
echo
print_status "Setup completed successfully at $(date)!"