docker.recipes

GoatCounter Analytics

beginner

Simple, privacy-friendly web analytics without tracking users.

Overview

GoatCounter is an open-source, privacy-focused web analytics platform created by Martin Tournoij that provides website traffic insights without tracking individual users or violating privacy. Unlike traditional analytics solutions that collect personal data and use cookies, GoatCounter focuses on aggregate statistics while respecting visitor privacy and GDPR compliance. It offers a lightweight alternative to Google Analytics with essential metrics like page views, referrers, browser statistics, and geographic data. This deployment combines the GoatCounter analytics service with a PostgreSQL database backend. The goatcounter container runs the web application and analytics engine, while the db service provides persistent data storage using PostgreSQL 15 Alpine. The two services communicate over a dedicated Docker network, with GoatCounter configured to connect to PostgreSQL using environment variables for database credentials. This stack is ideal for website owners, bloggers, small businesses, and organizations that prioritize visitor privacy while still needing meaningful analytics data. The combination offers the reliability of PostgreSQL for data persistence with GoatCounter's privacy-first approach, making it perfect for compliance-conscious environments or anyone seeking an ethical alternative to tracking-heavy analytics platforms.

Key Features

  • Privacy-first analytics with no personal data collection or tracking cookies
  • PostgreSQL backend for reliable data persistence and complex query capabilities
  • Real-time visitor statistics and page view tracking without user identification
  • Built-in referrer analysis showing traffic sources and external links
  • Geographic visitor distribution based on IP addresses without storing personal data
  • Browser and device statistics for technical insights without fingerprinting
  • Lightweight JavaScript tracking code with minimal performance impact
  • GDPR and privacy regulation compliant analytics collection

Common Use Cases

  • 1Privacy-conscious websites needing analytics without visitor tracking
  • 2Small business websites requiring basic traffic insights and referrer data
  • 3Personal blogs and portfolios tracking readership without compromising visitor privacy
  • 4Organizations in regulated industries needing GDPR-compliant analytics
  • 5Educational institutions monitoring website usage while protecting student privacy
  • 6Non-profit organizations tracking outreach effectiveness without data collection concerns
  • 7Development teams needing lightweight analytics for internal projects and documentation sites

Prerequisites

  • Docker and Docker Compose installed on the host system
  • Minimum 1GB RAM for PostgreSQL database operations and GoatCounter processing
  • Port 8080 available for GoatCounter web interface access
  • DB_PASSWORD environment variable configured for database authentication
  • Basic understanding of JavaScript integration for adding tracking code to websites
  • Command-line access for initial site creation and GoatCounter configuration

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 goatcounter:
3 image: ghcr.io/arp242/goatcounter:latest
4 container_name: goatcounter
5 environment:
6 - GOATCOUNTER_DB=postgresql://goatcounter:${DB_PASSWORD}@db/goatcounter?sslmode=disable
7 command: serve -listen :8080 -tls none
8 ports:
9 - "8080:8080"
10 depends_on:
11 - db
12 networks:
13 - goatcounter-network
14 restart: unless-stopped
15
16 db:
17 image: postgres:15-alpine
18 container_name: goatcounter-db
19 environment:
20 - POSTGRES_USER=goatcounter
21 - POSTGRES_PASSWORD=${DB_PASSWORD}
22 - POSTGRES_DB=goatcounter
23 volumes:
24 - postgres-data:/var/lib/postgresql/data
25 networks:
26 - goatcounter-network
27 restart: unless-stopped
28
29volumes:
30 postgres-data:
31
32networks:
33 goatcounter-network:
34 driver: bridge

.env Template

.env
1# GoatCounter
2DB_PASSWORD=secure_goatcounter_password
3
4# Create first user: goatcounter db create site -createdb -vhost=stats.example.com -user.email=you@example.com

Usage Notes

  1. 1Web UI at http://localhost:8080
  2. 2Create site via CLI first
  3. 3Add count.js to websites
  4. 4No personal data collection
  5. 5Lightweight and fast

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

goatcounter
goatcounter:
  image: ghcr.io/arp242/goatcounter:latest
  container_name: goatcounter
  environment:
    - GOATCOUNTER_DB=postgresql://goatcounter:${DB_PASSWORD}@db/goatcounter?sslmode=disable
  command: serve -listen :8080 -tls none
  ports:
    - "8080:8080"
  depends_on:
    - db
  networks:
    - goatcounter-network
  restart: unless-stopped
db
db:
  image: postgres:15-alpine
  container_name: goatcounter-db
  environment:
    - POSTGRES_USER=goatcounter
    - POSTGRES_PASSWORD=${DB_PASSWORD}
    - POSTGRES_DB=goatcounter
  volumes:
    - postgres-data:/var/lib/postgresql/data
  networks:
    - goatcounter-network
  restart: unless-stopped

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 goatcounter:
5 image: ghcr.io/arp242/goatcounter:latest
6 container_name: goatcounter
7 environment:
8 - GOATCOUNTER_DB=postgresql://goatcounter:${DB_PASSWORD}@db/goatcounter?sslmode=disable
9 command: serve -listen :8080 -tls none
10 ports:
11 - "8080:8080"
12 depends_on:
13 - db
14 networks:
15 - goatcounter-network
16 restart: unless-stopped
17
18 db:
19 image: postgres:15-alpine
20 container_name: goatcounter-db
21 environment:
22 - POSTGRES_USER=goatcounter
23 - POSTGRES_PASSWORD=${DB_PASSWORD}
24 - POSTGRES_DB=goatcounter
25 volumes:
26 - postgres-data:/var/lib/postgresql/data
27 networks:
28 - goatcounter-network
29 restart: unless-stopped
30
31volumes:
32 postgres-data:
33
34networks:
35 goatcounter-network:
36 driver: bridge
37EOF
38
39# 2. Create the .env file
40cat > .env << 'EOF'
41# GoatCounter
42DB_PASSWORD=secure_goatcounter_password
43
44# Create first user: goatcounter db create site -createdb -vhost=stats.example.com -user.email=you@example.com
45EOF
46
47# 3. Start the services
48docker compose up -d
49
50# 4. View logs
51docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/goatcounter-analytics/run | bash

Troubleshooting

  • GoatCounter shows database connection errors: Verify DB_PASSWORD environment variable matches between goatcounter and db services
  • Web interface not accessible at localhost:8080: Check that port 8080 is not used by other services and containers are running
  • Site creation fails or no data appears: Use docker exec to run goatcounter create commands inside the container before adding tracking code
  • PostgreSQL container fails to start: Ensure postgres-data volume permissions are correct and sufficient disk space is available
  • Tracking code not recording visits: Verify count.js is properly loaded from the GoatCounter instance and not blocked by ad blockers
  • Database performance issues with large datasets: Monitor PostgreSQL memory usage and consider increasing container memory limits for the db service

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space