A production-grade Bash script that automates the complete deployment of Dockerized applications to remote Linux servers with Nginx reverse proxy configuration.
- Automated Docker & Nginx installation
- Git repository cloning with PAT authentication
- Support for both Dockerfile and docker-compose.yml
- Automatic Nginx reverse proxy configuration
- Comprehensive error handling and logging
- Port conflict resolution
- Idempotent deployment (safe to run multiple times)
- Support for Ubuntu/Debian and RHEL/CentOS/Fedora
- Cleanup mode for resource removal
- Bash 4.0+
- Git
- SSH client
- rsync (optional, script will fallback to scp)
- Ubuntu/Debian or RHEL/CentOS/Fedora
- SSH access with key-based authentication
- Sudo privileges
git clone https://github.com/cf-cloud89/Dockerized-App-Deployment-Script.git
cd Dockerized-App-Deployment-Script
chmod +x deploy.shEnsure your application has either:
- Dockerfile - for single container apps
- docker-compose.yml - for multi-container apps
./deploy.shThe script will prompt you for:
- Git repository URL
- Personal Access Token (PAT)
- Branch name (default: main)
- SSH username
- Server IP address
- SSH key path (default: ~/.ssh/id_rsa)
- Application port
http://<YOUR_SERVER_IP>./deploy.sh./deploy.sh --cleanupImportant: Your application MUST bind to 0.0.0.0, not localhost.
- Go to GitHub → Settings → Developer settings → Personal access tokens (classic)
- Generate new token
- Select scope
- Copy token and use when prompted by script
# Generate SSH key if needed
ssh-keygen -t rsa -b 4096 -f ~/.ssh/<key_name>
# Copy to server
ssh-copy-id -i ~/.ssh/<key_name>.pub user@server-ip
# Test connection
ssh -i ~/.ssh/<key_name> user@server-ip- Collects Parameters - Validates all user inputs
- Clones Repository - Authenticates and pulls your code
- Tests SSH Connection - Verifies server access
- Prepares Environment - Installs Docker, Docker Compose, Nginx
- Deploys Application - Builds and runs Docker containers
- Configures Nginx - Sets up reverse proxy on port 80
- Validates Deployment - Tests all services and endpoints
- Logs Everything - Creates timestamped deployment logs
User Input → Clone Repo → SSH Test → Install Dependencies
↓
Stop Old Containers → Build Image → Run Container
↓
Configure Nginx → Test Endpoints → Success!
All operations are logged to timestamped files:
deploy_YYYYMMDD_HHMMSS.logCheck logs for debugging:
cat deploy_20251023_143000.log# Check SSH key permissions
chmod 600 ~/.ssh/<key_name>
# Test connection
ssh -vvv -i ~/.ssh/<key_name> user@server-ipThe script automatically stops conflicting containers. If issues persist:
# On remote server
docker ps
docker stop container-name# Check container logs
ssh user@server-ip
docker logs container-name
# Check Nginx
sudo systemctl status nginx
sudo tail -f /var/log/nginx/error.logRemote Server:
- Ubuntu 20.04, 22.04, 24.04
- Debian 10, 11, 12
- RHEL 8, 9
- CentOS 8, 9
- Fedora 38, 39, 40
Local Machine:
- Any Unix-like system with Bash 4.0+
- PAT tokens are never logged
- SSH keys require correct permissions (600)
- Uses key-based authentication only
- All credentials are user-provided at runtime
Dockerized-App-Deployment-Script/
├── deploy.sh # Main deployment script
├── README.md # This file
├── server.py # Replace with your app
├── Dockerfile # Replace with your Dockerfile or docker-compose.yml file
└── deploy_*.log # Generated log files
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Made with ❤️ for the DevOps Community