Automated Docker Deployment Script
A robust, production-grade Bash automation tool for setting up, deploying, and managing Dockerized applications on remote Linux servers.
This script simplifies DevOps workflows by automating repository setup, server provisioning, Docker installation, Nginx configuration, and container deployment - all securely over SSH.
๐ Features
- ๐ Secure SSH-based remote automation
- ๐ณ Automated Docker + Docker Compose installation
- ๐ Nginx reverse proxy with optional SSL support
- ๐ง Smart idempotency โ re-runs without breaking setups
- ๐ชฃ Auto-clones or pulls latest changes from GitHub (using PAT)
- ๐งฉ Builds and deploys Docker containers or Compose stacks
- ๐ Health checks and deployment validation
- ๐ Clear, color-coded logging
- ๐งน Optional cโฆ
Automated Docker Deployment Script
A robust, production-grade Bash automation tool for setting up, deploying, and managing Dockerized applications on remote Linux servers.
This script simplifies DevOps workflows by automating repository setup, server provisioning, Docker installation, Nginx configuration, and container deployment - all securely over SSH.
๐ Features
- ๐ Secure SSH-based remote automation
- ๐ณ Automated Docker + Docker Compose installation
- ๐ Nginx reverse proxy with optional SSL support
- ๐ง Smart idempotency โ re-runs without breaking setups
- ๐ชฃ Auto-clones or pulls latest changes from GitHub (using PAT)
- ๐งฉ Builds and deploys Docker containers or Compose stacks
- ๐ Health checks and deployment validation
- ๐ Clear, color-coded logging
- ๐งน Optional cleanup mode (
--cleanup) for safe resets
๐งฐ Prerequisites
Before running the script, ensure you have:
- A remote Linux server (Ubuntu 20.04+ recommended)
- SSH access with key-based authentication
- sudo privileges on the target server
- A GitHub Personal Access Token (PAT) for private repos
- Bash 5.0+,
ssh, andscpinstalled locally
๐ป Supported Platforms
| OS Distribution | Status | Notes |
|---|---|---|
| Ubuntu 20.04+ | โ Supported | Default target |
| Debian 11+ | โ ๏ธ Partial | Some commands may vary |
| Other Linux Distros | โ ๏ธ Partial | Untested, may need adjustments |
โ๏ธ Installation
Clone this project and make the script executable:
git clone https://github.com/KellsCodes/automated-deploy.git
cd automated-deploy
chmod +x deploy.sh
๐ฆ Usage
Run the deployment script:
./deploy.sh
Youโll be prompted for the following inputs:
| Variable | Description |
|---|---|
| GIT_REPO_URL | The HTTPS URL of your Git repository |
| GIT_BRANCH | Branch to deploy (e.g., main, develop) |
| SERVER_IP | Public IP of your remote server |
| SSH_USER | Username for SSH connection |
| SSH_KEY_PATH | Path to your .pem private key (e.g. ~/.ssh/aws-key.pem) |
| APP_PORT | Application port exposed in Docker |
| GIT_PAT | GitHub Personal Access Token (for private repos) |
Once executed, the script will:
- Clone or update the repository.
- SSH into the remote server.
- Install or update Docker, Compose, and Nginx.
- Transfer files securely.
- Build and run containers.
- Configure Nginx reverse proxy.
- Validate app health and connectivity.
๐ Deployment Lifecycle
- Clone / Update Repo โ Authenticates with PAT and syncs the specified branch.
- SSH Connection โ Establishes secure access to remote host.
- Environment Setup โ Installs Docker, Compose, Nginx, and dependencies.
- Deployment โ Transfers files, builds images, and starts containers.
- Reverse Proxy Setup โ Configures Nginx to forward requests to the app.
- Verification โ Checks container and port health.
- Idempotency Check โ Ensures safe re-runs without breaking live setups.
๐งน Cleanup (Optional)
To remove deployed containers, images, and Nginx configs, use:
./deploy.sh --cleanup
This safely removes Docker containers, images, and related deployment artifacts.
๐ Security Considerations
- Use key-based SSH authentication (no password logins).
- Keep your PAT secure โ never hardcode it.
- Limit server access to trusted IPs using firewall or security groups.
- Run deployments with least-privilege principles.
๐งฉ CI/CD Integration
This script can be integrated into CI/CD pipelines (e.g., GitHub Actions, GitLab CI, Jenkins) by providing environment variables non-interactively:
GIT_REPO_URL=https://github.com/KellsCodes/automated-deploy.git GIT_BRANCH=main SERVER_IP=1.2.3.4 SSH_USER=ubuntu SSH_KEY_PATH=~/.ssh/server-key.pem APP_PORT=8080 GIT_PAT=your_pat_here ./deploy.sh
๐ชต Logging & Monitoring
- All operations are logged in real time with color-coded status indicators.
- You can redirect logs to a file for auditing:
./deploy.sh | tee deploy.log
๐ง Troubleshooting
| Issue | Possible Fix |
|---|---|
| SSH connection fails | Ensure correct IP, SSH key, and security group allow port 22 |
| Permission denied (publickey) | Verify the .pem file path and permissions (chmod 400 key.pem) |
| 403 during clone | Ensure the PAT has repo and read:packages access |
| Port already in use | Stop old containers or change $APP_PORT |
| Nginx reload fails | Check /etc/nginx/sites-available/ for syntax errors |
๐ค Contributing
Contributions are welcome! Open an issue or submit a pull request to enhance features or add platform support.
๐ License
MIT License ยฉ 2025 KellsCodes
๐จโ๐ป Maintainers
Author: Ifeanyi Nworji GitHub: @KellsCodes