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 files:
Create a new directory for SparkyFitness and navigate into it. Then, download the necessary
docker-compose.ymland.envfiles.mkdir sparkyfitness && cd sparkyfitness curl -o docker-compose.yml https://raw.githubusercontent.com/CodeWithCJ/SparkyFitness/main/docker/docker-compose.prod.yml curl -o .env https://raw.githubusercontent.com/CodeWithCJ/SparkyFitness/main/docker/.env.example - Configure Environment Variables:
The
docker-compose.ymlfile relies on environment variables defined in a.envfile. Open the downloaded.envfile 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.exampleon GitHub
For a comprehensive list of all available environment variables and their detailed descriptions, please refer to the Environment Variables documentation. - Start the Application:
From within the
sparkyfitnessdirectory (wheredocker-compose.ymlis located), pull the latest images and start the application services:docker 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:15-alpine - Purpose: The PostgreSQL database server for storing application data.
- Data Persistence: Data is persisted in a Docker volume mapped to
../postgresqlon your host, 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:
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 stop
To stop and remove all services, networks, and volumes (this will delete your database data!):
docker compose down -v
