/ Home
Docker with Langfuse Local Setup Guide
This guide provides steps to set up Langfuse locally using Docker and run a Python tracing example.
Prerequisites
- Git
- Docker
- Python 3.x
- pip
Setup Steps
Step 1: Clone the Langfuse Repository
First, clone the Langfuse repository and navigate into its directory:
git clone https://github.com/langfuse/langfuse.git
cd langfuse
Step 2: Generate NEXTAUTH_SECRET Key
Generate a secure secret for NEXTAUTH_SECRET. Open your terminal and run the following command:
openssl rand -base64 32
Copy the output, as you will need it for the .env file.
Step 3: Prepare Langfuse Keys
You will need to create LANGFUSE_SECRET_KEY and LANGFUSE_PUBLIC_KEY. These are typically generated by Langfuse itself or can be set to arbitrary values for local development. For local setup, you can use any string values.
Set LANGFUSE_HOST to http://localhost:3000.
Step 4: Configure GROQ_API_KEY for Groq Models
If you plan to use Groq models in your application, you can provide your API key using the GROQ_API_KEY environment variable.
Step 1: Get Your Groq API Key Sign up or log in to your Groq account at https://console.groq.com.
Navigate to your API section and generate a new API key.
Step 5: Configure Environment Variables
Create a .env file in the root of the langfuse directory (or modify the existing one) with the following content. Replace the placeholder values with your generated keys.
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/langfuse
LANGFUSE_SECRET_KEY=your_langfuse_secret_key_here
LANGFUSE_PUBLIC_KEY=your_langfuse_public_key_here
LANGFUSE_HOST=http://localhost:3000
# NEXTAUTH_SECRET=$(openssl rand -base64 32)
NEXTAUTH_SECRET=your_generated_nextauth_secret_here
TELEMETRY_ENABLED=false
GROQ_API_KEY= # Optional: Your Groq API key if you plan to use Groq models
Note: Ensure you replace your_langfuse_secret_key_here, your_langfuse_public_key_here, and your_generated_nextauth_secret_here with actual values.
Step 6: Configure NEXTAUTH_SECRET in docker-compose.yml
To ensure secure authentication for the Langfuse web interface, you need to set the NEXTAUTH_SECRET environment variable in your docker-compose.yml file.
Reference it in your docker-compose.yml under the langfuse-web service:
langfuse-web: image: ghcr.io/langfuse/langfuse:latest restart: always depends_on: *langfuse-depends-on ports: - 3000:3000 environment: «: *langfuse-worker-env NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
Step 7: Start Langfuse Services with Docker Compose
From the langfuse directory, run Docker Compose to start the Langfuse backend and frontend services:
docker-compose up
Once the services are up and running, you can access the Langfuse UI in your browser at: http://localhost:3000
Step 8: Run the Python Tracing Example
Open a new terminal (while docker-compose up is still running in the first terminal). Navigate back to your project directory (where lfdockerlocal.py is located) and run the Python tracing script:
python lfdockerlocal.py
This script will send traces to your locally running Langfuse instance.
Step 9: View Langfuse Traces
After running the Python script, refresh the Langfuse UI at http://localhost:3000 to view the generated traces.