diff --git a/docker-compose.yml b/docker-compose.yml index 189dde5e3e1..366fbe51b5a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,67 +1,66 @@ -services: - litellm: - build: - context: . - args: - target: runtime - image: ghcr.io/berriai/litellm:main-stable - ######################################### - ## Uncomment these lines to start proxy with a config.yaml file ## - # volumes: - # - ./config.yaml:/app/config.yaml <<- this is missing in the docker-compose file currently - # command: - # - "--config=/app/config.yaml" - ############################################## - ports: - - "4000:4000" # Map the container port to the host, change the host port if necessary - environment: - DATABASE_URL: "postgresql://llmproxy:dbpassword9090@db:5432/litellm" - STORE_MODEL_IN_DB: "True" # allows adding models to proxy via UI - env_file: - - .env # Load local .env file - depends_on: - - db # Indicates that this service depends on the 'db' service, ensuring 'db' starts first - healthcheck: # Defines the health check configuration for the container - test: [ "CMD-SHELL", "wget --no-verbose --tries=1 http://localhost:4000/health/liveliness || exit 1" ] # Command to execute for health check - interval: 30s # Perform health check every 30 seconds - timeout: 10s # Health check command times out after 10 seconds - retries: 3 # Retry up to 3 times if health check fails - start_period: 40s # Wait 40 seconds after container start before beginning health checks - - db: - image: postgres:16 - restart: always - container_name: litellm_db - environment: - POSTGRES_DB: litellm - POSTGRES_USER: llmproxy - POSTGRES_PASSWORD: dbpassword9090 - ports: - - "5432:5432" - volumes: - - postgres_data:/var/lib/postgresql/data # Persists Postgres data across container restarts - healthcheck: - test: ["CMD-SHELL", "pg_isready -d litellm -U llmproxy"] - interval: 1s - timeout: 5s - retries: 10 - - prometheus: - image: prom/prometheus - volumes: - - prometheus_data:/prometheus - - ./prometheus.yml:/etc/prometheus/prometheus.yml - ports: - - "9090:9090" - command: - - "--config.file=/etc/prometheus/prometheus.yml" - - "--storage.tsdb.path=/prometheus" - - "--storage.tsdb.retention.time=15d" - restart: always - -volumes: - prometheus_data: - driver: local - postgres_data: - name: litellm_postgres_data # Named volume for Postgres data persistence - +services: + litellm: + build: + context: . + args: + target: runtime + image: ghcr.io/berriai/litellm:main-stable + ######################################### + ## Uncomment these lines to start proxy with a config.yaml file ## + # volumes: + # - ./config.yaml:/app/config.yaml <<- this is missing in the docker-compose file currently + # command: + # - "--config=/app/config.yaml" + ############################################## + ports: + - "4000:4000" # Map the container port to the host, change the host port if necessary + environment: + DATABASE_URL: "postgresql://llmproxy:dbpassword9090@db:5432/litellm" + STORE_MODEL_IN_DB: "True" # allows adding models to proxy via UI + env_file: + - .env # Load local .env file + depends_on: + - db # Indicates that this service depends on the 'db' service, ensuring 'db' starts first + healthcheck: # Defines the health check configuration for the container + test: [ "CMD-SHELL", "wget --no-verbose --tries=1 http://localhost:4000/health/liveliness || exit 1" ] # Command to execute for health check + interval: 30s # Perform health check every 30 seconds + timeout: 10s # Health check command times out after 10 seconds + retries: 3 # Retry up to 3 times if health check fails + start_period: 40s # Wait 40 seconds after container start before beginning health checks + + db: + image: postgres:16 + restart: always + container_name: litellm_db + environment: + POSTGRES_DB: litellm + POSTGRES_USER: llmproxy + POSTGRES_PASSWORD: dbpassword9090 + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data # Persists Postgres data across container restarts + healthcheck: + test: ["CMD-SHELL", "pg_isready -d litellm -U llmproxy"] + interval: 1s + timeout: 5s + retries: 10 + + prometheus: + image: prom/prometheus + volumes: + - prometheus_data:/prometheus + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + command: + - "--config.file=/etc/prometheus/prometheus.yml" + - "--storage.tsdb.path=/prometheus" + - "--storage.tsdb.retention.time=15d" + restart: always + +volumes: + prometheus_data: + driver: local + postgres_data: + name: litellm_postgres_data # Named volume for Postgres data persistence diff --git a/docker/Dockerfile.non_root b/docker/Dockerfile.non_root index d4e672251e9..3f204908f3f 100644 --- a/docker/Dockerfile.non_root +++ b/docker/Dockerfile.non_root @@ -33,7 +33,7 @@ WORKDIR /app # Install runtime dependencies USER root RUN apk upgrade --no-cache && \ - apk add --no-cache bash + apk add --no-cache bash libstdc++ ca-certificates openssl # Copy only necessary artifacts from builder stage for runtime COPY --from=builder /app/docker/entrypoint.sh /app/docker/prod_entrypoint.sh /app/docker/ @@ -86,4 +86,4 @@ ENTRYPOINT ["/app/docker/prod_entrypoint.sh"] # Append "--detailed_debug" to the end of CMD to view detailed debug logs # CMD ["--port", "4000", "--detailed_debug"] -CMD ["--port", "4000"] +CMD ["--port", "4000"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index 8dbc59d01bf..1c3c208988c 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,3 +1,65 @@ -# LiteLLM Docker +# Docker Development Guide -This is a minimal Docker Compose setup for self-hosting LiteLLM. \ No newline at end of file +This guide provides instructions for building and running the LiteLLM application using Docker and Docker Compose. + +## Prerequisites + +- Docker +- Docker Compose + +## Building and Running the Application + +To build and run the application, you will use the `docker-compose.yml` file located in the root of the project. This file is configured to use the `Dockerfile.non_root` for a secure, non-root container environment. + +### 1. Set the Master Key + +The application requires a `MASTER_KEY` for signing and validating tokens. You must set this key as an environment variable before running the application. + +Create a `.env` file in the root of the project and add the following line: + +``` +MASTER_KEY=your-secret-key +``` + +Replace `your-secret-key` with a strong, randomly generated secret. + +### 2. Build and Run the Containers + +Once you have set the `MASTER_KEY`, you can build and run the containers using the following command: + +```bash +docker-compose up -d --build +``` + +This command will: + +- Build the Docker image using `Dockerfile.non_root`. +- Start the `litellm`, `litellm_db`, and `prometheus` services in detached mode (`-d`). +- The `--build` flag ensures that the image is rebuilt if there are any changes to the Dockerfile or the application code. + +### 3. Verifying the Application is Running + +You can check the status of the running containers with the following command: + +```bash +docker-compose ps +``` + +To view the logs of the `litellm` container, run: + +```bash +docker-compose logs -f litellm +``` + +### 4. Stopping the Application + +To stop the running containers, use the following command: + +```bash +docker-compose down +``` + +## Troubleshooting + +- **`build_admin_ui.sh: not found`**: This error can occur if the Docker build context is not set correctly. Ensure that you are running the `docker-compose` command from the root of the project. +- **`Master key is not initialized`**: This error means the `MASTER_key` environment variable is not set. Make sure you have created a `.env` file in the project root with the `MASTER_KEY` defined.