Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: persist Langflow database across container restarts

Mike Pawlowski44830d3ab9b4
diff --git a/.gitignore b/.gitignore
index 02d024e00..8ee2c4059 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,9 +32,8 @@ wheels/
# OpenSearch data directory
opensearch-data/
-# Langflow data directory (ignore contents, keep directory via .gitkeep)
-/langflow-data/*
-!/langflow-data/.gitkeep
+# Langflow data directory
+langflow-data/
node_modules
diff --git a/Dockerfile.langflow b/Dockerfile.langflow
index 73793121b..abb651c74 100644
--- a/Dockerfile.langflow
+++ b/Dockerfile.langflow
@@ -1,13 +1,20 @@
+# syntax=docker/dockerfile:1.4
FROM langflowai/langflow:1.8.0
+# Switch to root so the entrypoint can fix data directory ownership before dropping privileges.
+# The base image runs as uid=1000; we restore that in the entrypoint script.
+USER root
+
# (+) Install uv
-# (+) Pre-create the Langflow data directory with correct ownership.
-# - This ensures named Docker volumes are initialised with uid=1000 so
-# the non-root container user can write to the mounted path.
-RUN set -ex \
- && pip install uv \
+# (+) Pre-create the Langflow data directory.
+# - For named Docker volumes, this seeds the volume with the correct path on first mount.
+# - For bind mounts, the entrypoint chowns the directory at startup.
+RUN pip install uv \
&& mkdir -p /app/langflow-data
+COPY --chmod=755 docker-entrypoint-langflow.sh /docker-entrypoint-langflow.sh
+
EXPOSE 7860
+ENTRYPOINT ["/docker-entrypoint-langflow.sh"]
CMD ["langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
diff --git a/Makefile b/Makefile
index 5fb3d948c..df179205c 100644
--- a/Makefile
+++ b/Makefile
@@ -79,7 +79,8 @@ endef
test test-unit test-integration test-ci test-ci-local test-sdk test-os-jwt lint \
backend frontend docling docling-stop install-be install-fe build-be build-fe build-os build-lf logs-be logs-fe logs-lf logs-os \
shell-be shell-lf shell-os restart status health db-reset clear-os-data flow-upload setup factory-reset \
- dev-branch build-langflow-dev stop-dev clean-dev logs-dev logs-lf-dev shell-lf-dev restart-dev status-dev
+ dev-branch build-langflow-dev stop-dev clean-dev logs-dev logs-lf-dev shell-lf-dev restart-dev status-dev \
+ ensure-langflow-data
all: help
@@ -319,7 +320,10 @@ help_utils: ## Show utility commands
# DEVELOPMENT ENVIRONMENTS
######################
-dev: ## Start full stack with GPU support
+ensure-langflow-data: ## Create the langflow-data directory if it does not exist
+ @mkdir -p langflow-data
+
+dev: ensure-langflow-data ## Start full stack with GPU support
@echo "$(YELLOW)Starting OpenRAG with GPU support...$(NC)"
$(COMPOSE_CMD) -f docker-compose.yml -f docker-compose.gpu.yml up -d
@echo "$(PURPLE)Services started!$(NC)"
@@ -329,7 +333,7 @@ dev: ## Start full stack with GPU support
@echo " $(CYAN)OpenSearch:$(NC) http://localhost:9200"
@echo " $(CYAN)Dashboards:$(NC) http://localhost:5601"
-dev-cpu: ## Start full stack with CPU only
+dev-cpu: ensure-langflow-data ## Start full stack with CPU only
@echo "$(YELLOW)Starting OpenRAG with CPU only...$(NC)"
$(COMPOSE_CMD) up -d
@echo "$(PURPLE)Services started!$(NC)"
@@ -339,7 +343,7 @@ dev-cpu: ## Start full stack with CPU only
@echo " $(CYAN)OpenSearch:$(NC) http://localhost:9200"
@echo " $(CYAN)Dashboards:$(NC) http://localhost:5601"
-dev-local: ## Start infrastructure for local development
+dev-local: ensure-langflow-data ## Start infrastructure for local development
@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"
$(COMPOSE_CMD) -f docker-compose.yml -f docker-compose.gpu.yml up -d opensearch openrag-backend dashboards langflow
@echo "$(PURPLE)Infrastructure started!$(NC)"
@@ -350,7 +354,7 @@ dev-local: ## Start infrastructure for local development
@echo ""
@echo "$(YELLOW)Now run 'make backend' and 'make frontend' in separate terminals$(NC)"
-dev-local-cpu: ## Start infrastructure for local development, with CPU only
+dev-local-cpu: ensure-langflow-data ## Start infrastructure for local development, with CPU only
@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"
$(COMPOSE_CMD) up -d opensearch openrag-backend dashboards langflow
@echo "$(PURPLE)Infrastructure started!$(NC)"
@@ -361,7 +365,7 @@ dev-local-cpu: ## Start infrastructure for local development, with CPU only
@echo ""
@echo "$(YELLOW)Now run 'make backend' and 'make frontend' in separate terminals$(NC)"
-dev-local-build-lf: ## Start infrastructure for local development, building only Langflow image
+dev-local-build-lf: ensure-langflow-data ## Start infrastructure for local development, building only Langflow image
@echo "$(YELLOW)Building Langflow image...$(NC)"
$(COMPOSE_CMD) -f docker-compose.yml -f docker-compose.gpu.yml build langflow
@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"
@@ -374,7 +378,7 @@ dev-local-build-lf: ## Start infrastructure for local development, building only
@echo ""
@echo "$(YELLOW)Now run 'make backend' and 'make frontend' in separate terminals$(NC)"
-dev-local-build-lf-cpu: ## Start infrastructure for local development, building only Langflow image with CPU only
+dev-local-build-lf-cpu: ensure-langflow-data ## Start infrastructure for local development, building only Langflow image with CPU only
@echo "$(YELLOW)Building Langflow image (CPU)...$(NC)"
$(COMPOSE_CMD) build langflow
@echo "$(YELLOW)Starting infrastructure only (for local development)...$(NC)"
@@ -393,7 +397,7 @@ dev-local-build-lf-cpu: ## Start infrastructure for local development, building
# Usage: make dev-branch BRANCH=test-openai-responses
# make dev-branch BRANCH=feature-x REPO=https://github.com/myorg/langflow.git
-dev-branch: ## Build & run full stack with custom Langflow branch
+dev-branch: ensure-langflow-data ## Build & run full stack with custom Langflow branch
@echo "$(YELLOW)Building Langflow from branch: $(BRANCH)$(NC)"
@echo " $(CYAN)Repository:$(NC) $(REPO)"
@echo ""
@@ -409,7 +413,7 @@ dev-branch: ## Build & run full stack with custom Langflow branch
@echo " $(CYAN)OpenSearch:$(NC) http://localhost:9200"
@echo " $(CYAN)Dashboards:$(NC) http://localhost:5601"
-dev-branch-cpu: ## Build & run full stack with custom Langflow branch and CPU only mode
+dev-branch-cpu: ensure-langflow-data ## Build & run full stack with custom Langflow branch and CPU only mode
@echo "$(YELLOW)Building Langflow from branch: $(BRANCH)$(NC)"
@echo " $(CYAN)Repository:$(NC) $(REPO)"
@echo ""
@@ -436,7 +440,7 @@ stop-dev: ## Stop dev environment containers
$(COMPOSE_CMD) -f docker-compose.dev.yml down
@echo "$(PURPLE)Dev environment stopped.$(NC)"
-restart-dev: ## Restart dev environment
+restart-dev: ensure-langflow-data ## Restart dev environment
@echo "$(YELLOW)Restarting dev environment with branch: $(BRANCH)$(NC)"
$(COMPOSE_CMD) -f docker-compose.dev.yml down
GIT_BRANCH=$(BRANCH) GIT_REPO=$(REPO) $(COMPOSE_CMD) -f docker-compose.dev.yml up -d
@@ -528,7 +532,7 @@ factory-reset: ## Complete reset (stop, remove volumes, clear data, remove image
fi; \
if [ -d "langflow-data" ]; then \
echo "Removing langflow-data..."; \
- rm -rf langflow-data/* 2>/dev/null || true; \
+ rm -rf langflow-data; \
echo "$(PURPLE)langflow-data removed$(NC)"; \
fi; \
if [ -d "config" ]; then \
@@ -677,7 +681,7 @@ test-integration: ## Run integration tests (requires infrastructure)
@echo "$(YELLOW)Make sure to run 'make dev-local' first!$(NC)"
uv run pytest tests/integration/core/ -v
-test-ci: ## Start infra, run integration + SDK tests, tear down (uses DockerHub images)
+test-ci: ensure-langflow-data ## Start infra, run integration + SDK tests, tear down (uses DockerHub images)
@set -e; \
echo "$(YELLOW)Installing test dependencies...$(NC)"; \
uv sync --group dev; \
@@ -806,7 +810,7 @@ test-ci: ## Start infra, run integration + SDK tests, tear down (uses DockerHub
$(COMPOSE_CMD) down -v 2>/dev/null || true; \
exit $$TEST_RESULT
-test-ci-local: ## Same as test-ci but builds all images locally
+test-ci-local: ensure-langflow-data ## Same as test-ci but builds all images locally
@set -e; \
echo "$(YELLOW)Installing test dependencies...$(NC)"; \
uv sync --group dev; \
diff --git a/docker-entrypoint-langflow.sh b/docker-entrypoint-langflow.sh
new file mode 100644
index 000000000..550ddcd53
--- /dev/null
+++ b/docker-entrypoint-langflow.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+set -e
+
+# Fix ownership of the Langflow data directory so the container user (uid=1000) can write to it.
+# When the directory is bind-mounted from a host with a different UID (e.g. CI runners at uid=1001),
+# the container user cannot create files. Running chown here as root — before dropping privileges —
+# mirrors the pattern used by official database images (OpenSearch, PostgreSQL, Redis).
+chown -R 1000:1000 /app/langflow-data
+
+# Drop from root to uid=1000 and exec the main process.
+# Python is used for privilege drop — it is guaranteed to be present in the Langflow image
+# and requires no additional packages (unlike gosu or su-exec).
+exec python3 -c 'import os, sys; os.setgid(1000); os.setuid(1000); os.execvp(sys.argv[1], sys.argv[1:])' "$@"
diff --git a/langflow-data/.gitkeep b/langflow-data/.gitkeep
deleted file mode 100644
index e69de29bb..000000000