Docker Compose [Recommended]
This page provides instructions for installing and running SparkyFitness using Docker Compose. This method is recommended for most users as it simplifies the setup process.
Prerequisites
Before you begin, ensure you have the following installed:
- Docker Desktop: Includes Docker Engine, Docker Compose, and Docker CLI.
Installation Steps
Create a new folder and download
docker-compose.yml: Create a new directory for SparkyFitness and navigate into it.bashmkdir sparkyfitness && cd sparkyfitness curl -L -o docker-compose.yml https://raw.githubusercontent.com/CodeWithCJ/SparkyFitness/main/docker/docker-compose.prod.ymlConfigure Environment Variables (
.env): Choose the configuration method that best fits your needs:- ⚡ Interactive .env Generator (Recommended): Generate a tailored
.envfile with 1-click cryptographically secure passwords and secrets directly in your browser. - 📄 Minimal .env Starter Template: Download the 5-variable minimal template for rapid 60-second setup:bash
curl -L -o .env https://raw.githubusercontent.com/CodeWithCJ/SparkyFitness/main/docker/.env.simple.example - 📚 Full .env Reference / Documentation Guide: Complete reference containing all optional knobs (OIDC, SMTP, Rate Limiting, Proxy headers).
- ⚡ Interactive .env Generator (Recommended): Generate a tailored
Replace the placeholder values: Skip this if you used the generator — it fills them in for you. If you downloaded either template, open
.envand replace every placeholder before starting. The server fails its preflight checks while they are left as-is, and PostgreSQL would otherwise initialize with the publishedchangeme_db_password.SPARKY_FITNESS_DB_PASSWORD— any strong password.SPARKY_FITNESS_API_ENCRYPTION_KEY—openssl rand -hex 32(64 hex characters; the server rejects anything else).BETTER_AUTH_SECRET—openssl rand -base64 32(44 characters).SPARKY_FITNESS_FRONTEND_URL— the URL you will actually open the app at.
Start the Application: From within the
sparkyfitnessdirectory (wheredocker-compose.ymlis located), pull the latest images and start the application services:bashdocker compose pull && docker compose up -ddocker compose pull: Downloads the latest Docker images for the services.docker compose up -d: Starts the services defined in thedocker-compose.ymlfile in detached mode (in the background).
Services Overview
The docker-compose.prod.yml file defines three main services:
sparkyfitness-db:- Image:
postgres:18.3-alpine - Purpose: The PostgreSQL database server for storing application data.
- Data Persistence: Data is persisted to
./postgresqlon your host (override withDB_PATH), ensuring your data is not lost if containers are removed.
- Image:
sparkyfitness-server:- Image:
codewithcj/sparkyfitness_server:latest - Purpose: The backend Node.js application server.
- Environment Variables: Configured with necessary database connection details, logging level, API encryption key, JWT secret, and frontend URL.
- Dependencies: Depends on
sparkyfitness-dbto ensure the database is running before the server starts.
- Image:
sparkyfitness-frontend:- Image:
codewithcj/sparkyfitness:latest - Purpose: The frontend React application served by Nginx.
- Ports: Maps host port
3004to container port80(Nginx), making the frontend accessible viahttp://localhost:3004(or your configured domain). - Dependencies: Depends on
sparkyfitness-serverto ensure the backend is running.
- Image:
Optional Services (Commented out by default)
To enable these services, open your docker-compose.yml file and uncomment the relevant blocks.
sparkyfitness-garmin:- Image:
codewithcj/sparkyfitness_garmin:latest - Purpose: A dedicated microservice for syncing data directly from Garmin Connect.
- Image:
Accessing the Application
Once all services are up and running, you can access the SparkyFitness frontend in your web browser at the URL you configured for SPARKY_FITNESS_FRONTEND_URL (e.g., http://localhost:3004).
Stopping and Removing Services
To stop the running services without removing their data volumes:
docker compose stopTo stop and remove all services, networks, and volumes (this will delete your database data!):
docker compose down -v