A Prometheus-compatible metrics exporter for Docker container statistics.
- Exposes Docker container information and state as Prometheus metrics
- Connects to Docker daemon via Unix socket (
/var/run/docker.sock) - Provides metrics for container info, state, and total count
- Configurable port via
PORTenvironment variable
# Build the application
go build -o prometheus-docker-container-exporter
# Run with default port (8080)
./prometheus-docker-container-exporter
# Run with custom port
PORT=9090 ./prometheus-docker-container-exporter# Build and run with Docker Compose
docker-compose up --build
# Or build the image directly
docker build -t mountainpass/prometheus-docker-container-exporter:latest .
# Run the container
docker run -d \
--name prometheus-docker-container-exporter \
-p 8080:8080 \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
mountainpass/prometheus-docker-container-exporter:latestBuild and publish multi-platform images:
# Build and push directly to registry (recommended)
docker-compose -f docker-compose.multiplatform.yml build --push
# Or build first, then push separately
docker-compose -f docker-compose.multiplatform.yml build
docker-compose -f docker-compose.multiplatform.yml pushNote: For pushing to a registry, ensure you're logged in with docker login and have appropriate permissions to push to the mountainpass namespace.
The metrics are available at: http://localhost:8080/metrics (or your configured port)
docker_container_info: Information about Docker containers (labels: id, name, image, status)docker_container_state: State of Docker containers (1=running, 0=stopped)docker_containers_total: Total number of Docker containers
Add this to your prometheus.yml:
scrape_configs:
- job_name: 'docker-containers'
static_configs:
- targets: ['localhost:8080']
scrape_interval: 30s- Docker daemon running with accessible socket at
/var/run/docker.sock - Go 1.19 or later
- Tested with Docker API Version 1.43