# 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. * [Download Docker Desktop](https://www.docker.com/products/docker-desktop) ## Installation Steps 1. **Create a new folder and download Docker files**: Create a new directory for SparkyFitness and navigate into it. Then, download the necessary `docker-compose.yml` and `.env` files. ```bash mkdir sparkyfitness && cd sparkyfitness curl -L -o docker-compose.yml https://github.com/CodeWithCJ/SparkyFitness/releases/latest/download/docker-compose.prod.yml curl -L -o .env https://github.com/CodeWithCJ/SparkyFitness/releases/latest/download/default.env.example ``` 2. **Configure Environment Variables**: The `docker-compose.yml` file relies on environment variables defined in a `.env` file. Open the downloaded `.env` file in a text editor and update the variables to customize your setup. It's crucial to configure these variables correctly for the application to function as expected. For a complete list of all available variables and their detailed descriptions, please refer to the example environment file: [`.env.example` on GitHub](https://github.com/CodeWithCJ/SparkyFitness/blob/main/docker/.env.example) For a comprehensive list of all available environment variables and their detailed descriptions, please refer to the [Environment Variables documentation](/install/environment-variables). 3. **Start the Application**: From within the `sparkyfitness` directory (where `docker-compose.yml` is located), pull the latest images and start the application services: ```bash docker compose pull && docker compose up -d ``` * `docker compose pull`: Downloads the latest Docker images for the services. * `docker compose up -d`: Starts the services defined in the `docker-compose.yml` file in detached mode (in the background). ## Services Overview The `docker-compose.prod.yml` file defines three main services: * **`sparkyfitness-db`**: * **Image**: `postgres:15-alpine` * **Purpose**: The PostgreSQL database server for storing application data. * **Data Persistence**: Data is persisted in a Docker volume mapped to `../postgresql` on your host, ensuring your data is not lost if containers are removed. * **`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-db` to ensure the database is running before the server starts. * **`sparkyfitness-frontend`**: * **Image**: `codewithcj/sparkyfitness:latest` * **Purpose**: The frontend React application served by Nginx. * **Ports**: Maps host port `3004` to container port `80` (Nginx), making the frontend accessible via `http://localhost:3004` (or your configured domain). * **Dependencies**: Depends on `sparkyfitness-server` to ensure the backend is running. ### 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. ## 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: ```bash docker compose stop ``` To stop and remove all services, networks, and volumes (this will delete your database data!): ```bash docker compose down -v