7802854b3254e69e5c646f7d9991824fabfeec32
Jenkins Docker Deploy Example
A Statping-like status monitoring app that demonstrates a Jenkins pipeline for Docker build, push, and deploy. The app performs HTTP/HTTPS and TCP checks, stores history in SQLite, and provides a dashboard with reports.
App Features
- HTTP/HTTPS checks – Ping URLs, measure response time and status code (success = 2xx)
- TCP checks – Verify connectivity to host:port
- History storage – SQLite database persists check results
- Reports – Uptime %, avg/min/max latency, recent check history
Repository Structure
.
├── Jenkinsfile # Pipeline definition
├── Dockerfile # Application image
├── docker-compose.yml # Deployment compose (pulled by deploy host)
├── app.py # Entry point
├── app/
│ ├── main.py # Flask routes
│ ├── models.py # SQLite schema
│ ├── checker.py # HTTP/HTTPS and TCP check logic
│ └── scheduler.py # APScheduler for periodic checks
├── templates/ # HTML templates
├── static/ # CSS
├── requirements.txt
└── README.md
Manual Test
# Build and run locally
docker build -t myapp:test .
docker run -p 8080:8080 -v $(pwd)/data:/app/data myapp:test
# Visit http://localhost:8080
Add services from the dashboard (e.g. https://example.com, google.com:443 for TCP) and view reports.
Jenkins Pipeline
The pipeline:
- Builds a Docker image
- Pushes the image to a container registry (Docker Hub, etc.)
- SSHs to a deployment machine
- Clones (or pulls) this repo to get
docker-compose.yml - Deploys with
docker compose up -d
Prerequisites
Jenkins
- Docker installed and Jenkins user in
dockergroup - Pipeline and SSH Agent plugins
- Git for cloning
Jenkins Credentials
| ID | Type | Purpose |
|---|---|---|
docker-registry-credentials |
Username/Password | Docker Hub or registry login |
deploy-ssh-key |
SSH Username with private key | SSH to deploy host |
Deploy Host
- Docker and Docker Compose installed
- SSH access for the deploy user
- If using a private registry: run
docker loginon the deploy host
Configuration
Edit the environment block in Jenkinsfile:
environment {
DOCKER_REGISTRY = 'docker.io'
DOCKER_IMAGE = 'myorg/myapp'
DEPLOY_HOST = 'deploy-server.example.com'
DEPLOY_USER = 'deploy'
DEPLOY_PATH = '/opt/myapp'
GIT_REPO_URL = 'https://github.com/myorg/jenkins-docker-deploy-example.git'
}
First-Time Deploy Host Setup
sudo mkdir -p /opt/myapp
sudo chown deploy:deploy /opt/myapp
sudo usermod -aG docker deploy
The docker-compose.yml mounts ./data:/app/data for SQLite persistence. Ensure the deploy directory is writable.
Branch Behavior
- main → image tag
latest - other branches → image tag
{BUILD_NUMBER}-{GIT_SHA}
Description
Languages
Python
57.7%
HTML
29.3%
CSS
12.1%
Dockerfile
0.8%