Skip to content

Conversation

SohamKukreti
Copy link
Collaborator

Summary

Fixes #1411 - Docker Compose configuration was overriding .llm.env values with empty strings, causing LLM authentication failures.

Root Cause: The environment: section in docker-compose.yml used variable substitution syntax (${VAR:-}) that checks the shell environment and .env file (not .llm.env) for values. When variables weren't found, Docker Compose substituted empty strings, which then overwrote the values from .llm.env due to Docker Compose's precedence rules (environment: has higher precedence than env_file:).

Solution: Commented out the environment: section to allow .llm.env values to load directly into the container without being overwritten. This makes the Docker Compose behavior consistent with docker run --env-file .llm.env as documented.

List of files changed and why

  • docker-compose.yml - Commented out the environment: section (lines 10-18) that was overriding .llm.env values with empty strings. Added a warning comment explaining that uncommenting will cause .llm.env to be overwritten.

How Has This Been Tested?

Test Environment:

  • Docker Compose v2.x
  • Created .llm.env with GEMINI_API_KEY and LLM_PROVIDER=gemini/gemini-2.5-flash

Test Steps:

  1. Before fix (environment section uncommented):

    docker compose up -d
    docker exec crawl4ai-crawl4ai-1 env | grep -E "(GEMINI_API_KEY|LLM_PROVIDER)"
    # Result: GEMINI_API_KEY, LLM_PROVIDER was empty
    curl "http://localhost:11235/llm/https://example.com/?q=test"
    # Result: Authentication error - tried to use OpenAI without key (defaulted to openai provided as mentioned in config.yml)
  2. After fix (environment section commented):

    docker compose down && docker compose up -d
    docker exec crawl4ai-crawl4ai-1 env | grep -E "(GEMINI_API_KEY|LLM_PROVIDER)"
    # Result: Both GEMINI_API_KEY and LLM_PROVIDER properly loaded ✅
    curl "http://localhost:11235/llm/https://example.com/?q=test"
    # Result: {"answer":"..."} - Works with Gemini! ✅

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Note: Unit tests for Docker Compose configuration behavior would require Docker-in-Docker setup. The fix has been manually tested and verified to work as documented. The configuration change is a simplification (removal) rather than new code, making it inherently less error-prone.

References

…yml (#1411)

The docker-compose.yml had an `environment:` section with variable
substitutions (${VAR:-}) that was overriding values from .llm.env with
empty strings.

- Commented out the `environment:` section to prevent overwrites
- Added clear warning comment explaining the override behavior
- .llm.env values now load directly into container without interference
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/docker-compose-llm-env

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant