
Langflow is an open-source, low-code visual framework for building artificial intelligence (AI) agents, workflows, and retrieval-augmented generation (RAG) applications. Developers use its visual builder to assemble large language model (LLM) pipelines from prebuilt components and test them in an interactive Playground. Finished flows run as API endpoints or Model Context Protocol (MCP) servers without extra boilerplate code.
This article explains how to self-host a production-ready Langflow instance on a Linux server with Docker Compose. It covers PostgreSQL persistence, Traefik reverse proxying with automatic HTTPS certificates, authentication for the visual editor, and validation of the deployment through a RAG chatbot that answers questions from an uploaded document.
Before you begin, ensure that you:
langflow.example.com.Langflow reads its runtime configuration from environment variables, so a dedicated project directory with a .env file keeps credentials out of the Compose manifest.
Create the project directory and switch into it.
Generate a Langflow secret key and write it to the environment file.
Langflow encrypts stored credentials with this Fernet key. Without an explicit key, Langflow generates a random one at startup and encrypted values become unreadable after a restart.
Verify that the file contains the key without displaying its value.
Output:
Open the .env file with a text editor such as nano.
Add the following variables below the existing LANGFLOW_SECRET_KEY line. Replace every placeholder with your own values.
Save and close the file. Each group of variables controls a distinct part of the deployment:
LANGFLOW_HOSTNAME and LETSENCRYPT_EMAIL supply the domain for the Traefik routing rule and the contact address for certificate expiry notices.POSTGRES_* variables initialize the database container on first boot, and the Compose manifest reuses them in the Langflow connection string. Use only letters and numbers in the password, because symbols require %-encoding and $ conflicts with Compose interpolation.LANGFLOW_CONFIG_DIR and LANGFLOW_KNOWLEDGE_BASES_DIR place application data and knowledge base vectors on the same volume-mapped path. Without the second variable, Langflow writes knowledge bases outside that volume and a container replacement deletes your vector data.LANGFLOW_AUTO_LOGIN=False disables anonymous access, LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD define the administrator account that Langflow creates at startup, LANGFLOW_NEW_USER_IS_ACTIVE=False keeps new accounts inactive until the administrator approves them, and LANGFLOW_ENABLE_SUPERUSER_CLI=False blocks superuser creation from the command line.OPENAI_API_KEY supplies the LLM provider credential, which Langflow stores as an encrypted global variable.Restrict the environment file so that only its owner can read or modify it.
The stack runs three services. Traefik terminates HTTPS, Langflow serves the application on internal port 7860, and PostgreSQL stores flows, users, and settings. Langflow joins the proxy network with Traefik and the internal network with PostgreSQL, so the database stays unreachable from outside.
Create the docker-compose.yml file in the project directory.
Add the following service definitions to the file.
Save and close the file. The three services fit together as follows:
traefik service publishes ports 80 and 443, discovers only explicitly labeled containers through the read-only Docker socket, and registers a certificate resolver named le that completes the Automatic Certificate Management Environment (ACME) challenge on port 80 and redirects plain HTTP requests to HTTPS.langflow service pins the langflowai/langflow:1.11.3 image, the release that matches every interface step in this article. The Traefik labels route your domain to port 7860 inside the container, and the langflow-data volume persists LANGFLOW_CONFIG_DIR across restarts.postgres service pins the postgres:16-trixie image, which fixes the PostgreSQL version and the Debian base and prevents glibc collation mismatch warnings. It joins only the internal network, and its pg_isready health check gates the Langflow start.Start the stack in detached mode.
Docker Compose pulls the three images, creates the networks and volumes, and starts Langflow after the PostgreSQL health check passes.
Verify that all containers are running.
The output displays three running containers, with Traefik listening on ports 80 and 443 and PostgreSQL reporting a healthy status.
Check the Langflow logs to verify that the application started.
The first start takes a few minutes because Langflow runs its database migrations against PostgreSQL. The log stream ends with a startup banner when the application is ready.
Output:
Press Ctrl + C to stop following the logs. The localhost address applies inside the container only, and Traefik forwards your domain traffic to the same listener.
The stack now runs behind HTTPS, so the remaining configuration happens in the browser. Sign in with the administrator account and verify that Langflow registered the OpenAI credential.
Open a web browser and visit your Langflow domain, such as https://langflow.example.com.
Traefik requests a Let's Encrypt certificate after the stack starts. If the browser shows a certificate warning, wait a minute, and then reload the page. Because automatic login is off, Langflow redirects you to the /login page.
Log in with the values that you set for LANGFLOW_SUPERUSER and LANGFLOW_SUPERUSER_PASSWORD. The Langflow Projects page opens.
Verify the model provider. Click your profile icon in the header, select Settings, and then click Model Providers. The OpenAI provider appears as configured because Langflow detects the OPENAI_API_KEY variable at startup. Enable the models that you plan to use under Language Models and Embedding Models.
Verify the stored credential. In Settings, click Global Variables. A variable named OPENAI_API_KEY appears with the Credential type, which masks its value in the visual editor.
A RAG chatbot answers questions from your own documents instead of relying only on the model's training data. Langflow ships a Vector Store RAG template that pairs a retrieval flow with a knowledge base, which chunks a document, embeds it, and stores the vectors locally. A grounded answer in the Playground proves that ingestion, retrieval, and generation all work on the deployed stack.
The knowledge base handles document ingestion, so it needs an update only when the source content changes.
On the Projects page, click Knowledge below the list of projects.
Click Add Knowledge.
In the Create Knowledge Base pane, enter a name such as langflow_demo, select an OpenAI embedding model, and keep Chroma Local as the DB Provider. The Chroma Local provider stores the vectors on the server, so the knowledge base requires no external database account.
Click Add Files. Select a document from your local machine, such as a product manual or a policy document.
Keep the default values for Chunk Size, Chunk Overlap, and Separator, and then click Next Step.
Review the sample chunk in the Review & Build pane, and then click Create. Langflow splits the document into chunks, converts each chunk into a vector, and indexes the results.
Wait until the knowledge base Status changes to Ready, which means that the ingestion pipeline completed without errors.
The template arrives pre-connected, so setup comes down to two picks: the knowledge base and the chat model.
On the Projects page, click New Flow, and then select the Vector Store RAG template.
Review how the components connect. Chat Input sends each question to Knowledge as the Search Query and to Prompt as the {question} variable. Knowledge returns matching chunks, Parser extracts their text, and Prompt inserts that text as {context}. Agent generates the answer, and Chat Output returns it.
In the Knowledge component, keep Retrieve as the Mode, and select your langflow_demo knowledge base in the Knowledge field. Retrieval reuses the embedding model from ingestion, so query vectors and stored vectors stay comparable.
In the Agent component, select an OpenAI chat model in the Language Model field. The template preloads Agent Instructions with a retrieval-focused system prompt.
Review the Prompt component. Adjust the wording if you want a different tone, but keep the {context} and {question} placeholders intact.
The Playground provides a chat interface wired to the flow for validating the end-to-end pipeline.
Click Playground. A chat panel opens.
Type a question that only your uploaded document can answer, and then press Enter.
Read the response. The flow runs a semantic search against the knowledge base, pulls the most similar chunks, and instructs the language model to answer from that context.
Ask a follow-up question about a different part of the document to verify that retrieval covers the full file rather than a single chunk.
You have deployed Langflow on a Linux server with Docker Compose, with Traefik for TLS termination, and with PostgreSQL storing your flows, users, and settings. Superuser authentication protects the visual editor, an encrypted global variable holds the LLM provider credential, and a working Vector Store RAG chatbot answers questions from your uploaded document. For more configuration options, visit the Langflow documentation.
0 Comments
Be the first to comment and share your perspective with the community.