ai_perplexica/README.md
2025-03-28 04:44:39 +03:00

152 lines
4.0 KiB
Markdown

# How to Set Up and Self-Host Perplexica Using Docker
## 1. Preparing Your Development Environment
### Updating Dependencies
Before you start, it's essential to ensure your system has the necessary dependencies installed:
```bash
sudo apt update && sudo apt upgrade -y
```
This command updates your package lists and installs any new required packages.
### Installing Docker
Docker is crucial for containerizing and running Perplexica. Install Docker CE (for development) or Docker Hub (for production):
```bash
apt install docker.io docker-compose git -y
```
This will install Docker CE on your system, allowing you to create and run Docker containers.
## 2. Cloning the Perplexica Repository
To get access to the Perplexica codebase:
```bash
git clone https://github.com/ItzCrazyKns/Perplexica
cd Perplexica
```
Replace `[your-repository-url]` with the actual GitHub repository URL of your Perplexica project.
## 3. Configuring the Docker Compose File
### Understanding the Docker Compose File
The following YAML file configures a multi-service application:
```yaml
services:
searxng:
image: docker.io/searxng/searxng:latest
volumes:
- ./searxng:/etc/searxng:rw
ports:
- 4000:8080
networks:
- perplexica-network
restart: unless-stopped
ollama:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
environment:
- OLLAMA_HOST=0.0.0.0:11434
networks:
- perplexica-network
restart: unless-stopped
app:
image: itzcrazykns1337/perplexica:main
build:
context: .
dockerfile: app.dockerfile
environment:
- SEARXNG_API_URL=http://searxng:8080
- OLLAMA_API_URL=http://ollama:11434 # Added Ollama API URL
ports:
- 3000:3000
networks:
- perplexica-network
volumes:
- backend-dbstore:/home/perplexica/data
- uploads:/home/perplexica/uploads
- ./config.toml:/home/perplexica/config.toml
depends_on:
- ollama #Ensure ollama is started first
- searxng #Ensure searxng is started second
restart: unless-stopped
networks:
perplexica-network:
volumes:
backend-dbstore:
uploads:
ollama_data: # Add ollama volume so it does not get lost
```
### Explanation of Each Service
1. **searxng**:
- Uses the official `docker.io/searxng/searxng:latest` image.
- Listens on port 4000 and maps to Perplexica's 8080 endpoint.
2. **ollama**:
- Uses the Ollama image with CUDA support for GPU acceleration.
- Exposes port 11434, which is used by Perplexica for API communication.
3. **app** (Perplexica Service):
- Runs in a custom Docker image (`itzcrazykns1337/perplexica:main`).
- Exposes the application on port 3000.
- Maps local development files to host volumes for data persistence.
### Volume Configuration
Volumes ensure that data remains accessible after deployment:
- `backend-dbstore`: Stores the database used by Perplexica.
- `uploads`: Stores uploaded content (e.g., PDFs).
- `config.toml`: Stores configuration settings.
## 4. Building and Running the Application
After setting up the Docker Compose file, run these commands to deploy:
```bash
docker-compose down && docker-compose up --build -d
```
This command:
1. Removes existing containers (`docker-compose down`).
2. Builds and starts a new deployment (`docker-compose up --build -d`).
## 5. What If It Fails?
If the setup fails, clean all containers and volumes:
```bash
docker rm -v -f $(docker ps -qa)
docker rmi -f $(docker images -aq)
docker volume prune
docker system prune
sudo systemctl restart docker
```
Then, repeat the deployment steps.
## 6. Conclusion
By following these steps, you'll have a fully functional Perplexica application running on your local machine. The Docker setup ensures consistency across development environments and simplifies deployment to production.false