12 Docker Compose
Hunter Long edited this page 4 years ago

This page includes multiple docker-compose.yml setups for you to run. There are many environment variables for additional settings and features, checkout the Environment Variables Wiki to see them all.

Docker Image Version (tag latest semver) Docker Image Size (tag) Docker Image Size (tag) Docker Pulls

Database Configurations

Web Serving

Metrics


Docker Volumes

  • /app - Main Volume that you should mount to a directory on the host machine
  • /app/config.yml - Config file
  • /app/logs - Logs folder (rotates every 3 days)
  • /app/assets - Folder containing all CSS, SCSS, JS and other static files (if you use custom styling)
  • /app/statping.db - SQLite database file (if you're using SQLite)

Basic SQLite Connection

This docker-compose will start Statping on port 8080 and automatically run on a SQLite database.

statping:
  container_name: statping
  image: statping/statping
  restart: always
  ports:
    - 8080:8080
  volumes:
    - ./statping:/app
  environment:
    DB_CONN: sqlite

MySQL Connection

statping:
  container_name: statping
  image: statping/statping
  restart: always
  depends_on:
    - mysql
  ports:
    - 8080:8080
  volumes:
    - statping_data:/app
  links:
    - mysql
  environment:
    DB_CONN: mysql
    DB_HOST: mysql
    DB_PORT: 3306
    DB_DATABASE: statping
    DB_USER: root
    DB_PASS: password123

mysql:
  image: mysql:5.7
  volumes:
    - mysql_data:/var/lib/mysql
  restart: always
  ports:
    - 3306:3306
  environment:
    MYSQL_ROOT_PASSWORD: password123
    MYSQL_DATABASE: statping
    MYSQL_USER: root
    MYSQL_PASSWORD: password

Postgres

statping:
  container_name: statping
  image: statping/statping
  restart: always
  ports:
    - 8080:8080
  volumes:
    - statping_data:/app
  links:
    - postgres
  depends_on:
    - postgres
  environment:
    DB_CONN: postgres
    DB_HOST: postgres
    DB_PORT: 5432
    DB_DATABASE: statping
    DB_USER: root
    DB_PASS: password123

postgres:
  container_name: postgres
  image: postgres:10.0-alpine
  ports:
    - 5432:5432
  volumes:
    - pg_data:/var/lib/postgresql/data/pg_data
  environment:
    POSTGRES_PASSWORD: password123
    POSTGRES_DB: statping
    POSTGRES_USER: root
    POSTGRES_PORT: 5432
    PGDATA: /var/lib/postgresql/data/pg_data

Nginx Proxy Pass

The jwilder/nginx-proxy Docker image will automatically redirect a domain to a specific container.

statping:
  container_name: statping
  image: statping/statping
  restart: always
  volumes:
    - statping_data:/app
  environment:
    DB_CONN: sqlite
    VIRTUAL_HOST: demo.statping.com
    VIRTUAL_PORT: 8080

nginx:
  container_name: nginx
  image: jwilder/nginx-proxy
  ports:
    - 80:80
  volumes:
    - /var/run/docker.sock:/tmp/docker.sock:ro

Nginx Proxy Pass with SSL (jwilder/nginx-proxy)

Using the jwilder/nginx-proxy image along with jrcs/docker-letsencrypt-nginx-proxy-companion you'll be able to automatically generate SSL certificates for your Statping instance.

statping:
  container_name: statping
  image: statping/statping
  restart: always
  volumes:
    - statping_data:/app
  environment:
    DB_CONN: sqlite
    LETSENCRYPT_HOST: demo.statping.com
    VIRTUAL_HOST: demo.statping.com
    VIRTUAL_PORT: 8080

nginx:
  container_name: nginx
  image: jwilder/nginx-proxy
  restart: always
  ports:
    - 80:80
    - 443:443
  volumes:
    - /var/run/docker.sock:/tmp/docker.sock:ro
    - cert_volume:/etc/nginx/certs
    - vhost_volume:/etc/nginx/vhost.d
    - html_volume:/usr/share/nginx/html
  environment:
    DEFAULT_HOST: demo.statping.com
  labels:
    - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"

nginx-ssl:
  container_name: nginx-ssl
  image: jrcs/letsencrypt-nginx-proxy-companion
  restart: always
  links:
    - nginx
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    - cert_volume:/etc/nginx/certs
    - vhost_volume:/etc/nginx/vhost.d
    - html_volume:/usr/share/nginx/html
  environment:
    DEFAULT_EMAIL: info@mydomain.com
    NGINX_PROXY_CONTAINER: nginx

Grafana Dashboard with Prometheus

Grafana is an awesome metric visualizer that allows you to create some awesome dashboards. We've already created a Grafana Dashboard that you can easy import! Checkout the Grafana Wiki and the Prometheus Exporter Wiki for more details.

prometheus.yml config file

This file should be mounted to /etc/prometheus/prometheus.yml in the Prometheus container.

global:
  scrape_interval:     30s
  evaluation_interval: 30s

scrape_configs:
  - job_name: 'statping'
    scrape_interval: 30s
    bearer_token: 'SECRET API KEY HERE'
    static_configs:
      - targets: ['statping:8080']

Be sure to replace SECRET API KEY HERE with your API Secret on the Settings page.

docker-compose.yml file for Statping, Grafana and Prometheus
statping:
  container_name: statping
  image: statping/statping
  restart: always
  volumes:
    - statping_data:/app
  environment:
    DB_CONN: sqlite
    LETSENCRYPT_HOST: demo.statping.com
    VIRTUAL_HOST: demo.statping.com
    VIRTUAL_PORT: 8080

prometheus:
  container_name: prometheus
  image: prom/prometheus:v2.0.0
  restart: always
  ports:
    - 9090:9090
  volumes:
    - prometheus.yml:/etc/prometheus/prometheus.yml # config file is above ^
    - prometheus_data:/prometheus
  links:
    - statping
  depends_on:
    - statping

grafana:
  container_name: grafana
  image: grafana/grafana
  restart: always
  ports:
    - 3000:3000
  volumes:
    - grafana_data:/var/lib/grafana
  environment:
    - GF_SECURITY_ADMIN_PASSWORD=password123
    - GF_USERS_ALLOW_SIGN_UP=false
  depends_on:
    - prometheus
  links:
    - prometheus

Traefik

This docker-compose stack will start Statping and Traefik v2.2. You may need to research the Traefik label configs and edit to your own needs. The Traefik server will run on port 80 and 443, and Statping on port 8080.

version: '3.4'

services:

  traefik:
    container_name: traefik
    image: traefik:v2.2.0
    restart: always
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --entrypoints.web.http.redirections.entryPoint.to=websecure
      - --entrypoints.web.http.redirections.entryPoint.scheme=https
      - --entrypoints.websecure.http.tls.certResolver=leresolverresolver
      - --providers.docker
      - --log=true
      - --log.level=INFO
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - frontend
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.rule=Host(`traefik.statping.com`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.middlewares=admin"
      - "traefik.http.routers.traefik.tls.certresolver=leresolver"
      - "traefik.http.routers.traefik.entrypoints=websecure"
      - "traefik.http.routers.http-catchall.entrypoints=web"
      - "traefik.http.routers.http-catchall.rule=HostRegexp(`{host:.+}`)"
      - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

  statping:
    container_name: statping
    image: statping/statping:latest
    restart: always
    networks:
      - frontend
    volumes:
      - ./statping_data:/app
    environment:
      DB_CONN: sqlite
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.statping.rule=Host(`demo.statping.com`)"
      - "traefik.http.routers.statping.tls.certresolver=leresolver"
      - "traefik.http.routers.statping.entrypoints=websecure"
      - "traefik.http.services.statping.loadbalancer.server.port=8080"

networks:
  frontend:
    driver: bridge