Overview
Showdown Trivia includes a complete Docker Compose setup that runs:- Application: Go web server
- MongoDB: Database for game data and user information
- Prometheus: Metrics collection and monitoring
- Grafana: Metrics visualization dashboard
Quick Start
Prerequisites
Ensure you have installed:
- Docker (version 20.10 or higher)
- Docker Compose (version 2.0 or higher)
Build and run
From the project root directory:This command will:
- Build the application Docker image
- Pull required images (MongoDB, Prometheus, Grafana)
- Start all services
- Create necessary networks and volumes
Access the application
Once all services are running, access:
- Application: http://localhost:8080
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
Service Configuration
Application Service
The main application is built using a multi-stage Dockerfile for optimized image size. Image: Built fromDockerfilePort: 8080
Container Name:
app
Environment Variables:
The application depends on MongoDB and will wait for it to be ready before starting.
MongoDB Service
Image:mongo:7.0.5Port: 27017
Database:
trivia
Default Credentials:
- Username:
admin - Password:
admin11
Prometheus Service
Image:prom/prometheus:v2.40.4Port: 9090 Configuration:
Prometheus is configured via
/etc/prometheus/prometheus.yml, mounted from:
Grafana Service
Image:grafana/grafana:9.3.0Port: 3000 Default Credentials:
- Username:
admin - Password:
devops123
- Configuration:
./deployments/grafana/datasources.yaml→/etc/grafana/provisioning/datasources/datasources.yaml - Data persistence: Named volume
grafana
Grafana is pre-configured with Prometheus as a data source through the provisioned datasources configuration.
Docker Compose File Structure
Dockerfile Overview
The application uses a multi-stage build for efficiency: Stage 1: Builder (golang:1.22.3-alpine3.18)- Downloads and verifies Go modules
- Copies source code
- Builds optimized binary with
-ldflags="-s"(strips debug info)
- Minimal Alpine Linux base
- Copies only the compiled binary
- Exposes port 8080
- Runs the application
The multi-stage build reduces the final image size significantly by excluding build tools and source code.
Port Mappings
| Service | Host Port | Container Port | Purpose |
|---|---|---|---|
| Application | 8080 | 8080 | Web application |
| MongoDB | 27017 | 27017 | Database access |
| Prometheus | 9090 | 9090 | Metrics collection |
| Grafana | 3000 | 3000 | Dashboard UI |
Common Commands
Data Persistence
The Grafana service uses a named volume (grafana) to persist:
- Dashboard configurations
- User preferences
- Custom queries and annotations
Customization
Change Application Port
Modify both the environment variable and port mapping:Use External MongoDB
Remove themongo service and update the application’s DB_URL:
Change Log Level
Modify theLOG_LEVEL environment variable:
Monitoring Setup
After starting the services:Access Grafana
Navigate to http://localhost:3000 and log in with:
- Username:
admin - Password:
devops123
Troubleshooting
Container fails to start
Check logs for the specific service:Port already in use
Find and stop the conflicting process:compose.yaml.
MongoDB connection issues
Ensure the MongoDB container is healthy:Production Considerations
Next Steps
Local Setup
Set up the development environment without Docker
Configuration
Understand all configuration options and environment variables