Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker 1.0.16 image does not work with Postgres #3524

Closed
mieslep opened this issue Aug 23, 2024 · 2 comments · Fixed by #3526
Closed

Docker 1.0.16 image does not work with Postgres #3524

mieslep opened this issue Aug 23, 2024 · 2 comments · Fixed by #3526
Assignees
Labels
bug Something isn't working

Comments

@mieslep
Copy link
Contributor

mieslep commented Aug 23, 2024

Bug Description

Running docker run -d langflowai/langflow:1.0.16 works just fine, but if you specify -e LANGFLOW_DATABASE_URL=postgres://...

you get errors:

Can't load plugin:                
sqlalchemy.dialects:postgres      

import_dbapi                      
    import psycopg2               
ModuleNotFoundError: No module    
named 'psycopg2'                  

Reproduction

Start a Docker instance for v1.0.16 that connects to a Postgres database using the LANGFLOW_DATABASE_URL environment vairable.

Expected behavior

Container starts and Langflow service runs as normal :)

Who can help?

No response

Operating System

Langflow Docker image

Langflow Version

1.0.16

Python Version

3.12

Screenshot

No response

Flow File

No response

@mieslep mieslep added the bug Something isn't working label Aug 23, 2024
Copy link

dosubot bot commented Aug 23, 2024

I found a similar open issue: No PostgreSQL driver in docker image for 1.0.16, which was last updated on August 22, 2024. The suggested solution is to modify the pyproject.toml file to include psycopg[binary]:

[tool.poetry.dependencies]
psycopg = { version = "3.1.9", extras = ["binary"] }

This change ensures that the binary version of the psycopg package is used, which can help with compatibility and performance.

Additionally, to resolve the issue with the Docker image, you can create a custom Dockerfile that installs the psycopg2 module. Here is an example:

  1. Create a Dockerfile for the Langflow service:

    FROM langflowai/langflow:1.0-alpha
    
    # Install psycopg2
    RUN pip install psycopg2-binary
    
    # Copy the rest of your application code if needed
    # COPY . /app
    
    # Set the working directory
    WORKDIR /app
    
    # Expose the necessary port
    EXPOSE 7860
    
    # Define the entry point
    CMD ["python", "-m", "langflow", "run"]
  2. Modify the docker-compose.yml to use the custom Dockerfile:

    version: "3.8"
    
    services:
      langflow:
        build:
          context: .
          dockerfile: Dockerfile
        ports:
          - "7860:7860"
        depends_on:
          - postgres
        environment:
          - LANGFLOW_DATABASE_URL=postgresql://langflow:langflow@postgres:5432/langflow
          - LANGFLOW_CONFIG_DIR=app/langflow
        volumes:
          - langflow-data:/app/langflow
    
      postgres:
        image: postgres:16
        environment:
          POSTGRES_USER: langflow
          POSTGRES_PASSWORD: langflow
          POSTGRES_DB: langflow
        ports:
          - "5432:5432"
        volumes:
          - langflow-postgres:/var/lib/postgresql/data
    
    volumes:
      langflow-postgres:
      langflow-data:

By building a custom Docker image that includes the psycopg2 module, you should be able to connect to the PostgreSQL database without encountering the ModuleNotFoundError [1][2].

To continue talking to Dosu, mention @dosu.

@italojohnny italojohnny self-assigned this Aug 23, 2024
@italojohnny
Copy link
Member

It seems the issue is related to PR #3292.

For now, if you can manually install the psycopg2 dependency in your container, I believe you should be able to continue your work until the problem is resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants