168 lines
4.1 KiB
Markdown

# 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.