Skip to main content
Version: 1.10.x

Deploy Langflow on Docker

tip

Podman can be used instead of Docker for all commands shown here. For more information, see the Podman documentation.

Running applications in Docker containers ensures consistent behavior across different systems and eliminates dependency conflicts.

You can use the Langflow Docker image to start a Langflow container.

This guide demonstrates several ways to deploy Langflow with Docker and Docker Compose:

  • Quickstart: Start a Langflow container with default values.
  • Use Docker Compose: Clone the Langflow repo, and then use Docker Compose to build the Langflow Docker container. This option provides more control over the configuration, including a persistent PostgreSQL database service, while still using the base Langflow Docker image.
  • Create a custom flow image: Use a Dockerfile to package a flow as a Docker image.
  • Create a custom Langflow image: Use a Dockerfile to package a custom Langflow Docker image that includes your own code, custom dependencies, or other modifications.
  • Upgrade the Langflow Docker image: Upgrade to a newer image without losing your database or flows by using persistent volumes and replacing only the container.

Quickstart: Start a local Langflow container​

With Docker installed and running on your system, run the following command:

docker run -p 7860:7860 -e LANGFLOW_AUTO_LOGIN=true langflowai/langflow:latest

Then, access Langflow at http://localhost:7860/.

This starts a pre-built Docker image with automatic login enabled for local development. For more control over the configuration, see Clone the repo and run the Langflow Docker container.

Clone the repo and run the Langflow Docker container​

Cloning the Langflow repository and using Docker Compose gives you more control over your configuration, allowing you to customize environment variables, use a persistent PostgreSQL database service (instead of the default SQLite database), and include custom dependencies.

The default deployment with Docker Compose includes the following:

  • Langflow service: Runs the latest Langflow image with PostgreSQL as the database.
  • PostgreSQL service: Provides persistent data storage for flows, users, and settings.
  • Persistent volumes: Ensures your data survives container restarts.

The complete Docker Compose configuration is available in docker_example/docker-compose.yml.

  1. Clone the Langflow repository:

    git clone https://github.com/langflow-ai/langflow.git
  2. Navigate to the docker_example directory:

    cd langflow/docker_example
  3. Create a .env file with the Langflow admin password:

    LANGFLOW_SUPERUSER_PASSWORD=replace-with-a-strong-password

    The default admin username is langflow.

  4. Run the Docker Compose file:

    docker compose up
  5. Access Langflow at http://localhost:7860/.

Customize your deployment​

You can customize the Docker Compose configuration to fit your specific deployment.

For example, to configure the container's database credentials using a .env file, do the following:

  1. Create a .env file with your database credentials in the same directory as docker-compose.yml:

    # Database credentials
    POSTGRES_USER=myuser
    POSTGRES_PASSWORD=mypassword
    POSTGRES_DB=langflow

    # Langflow configuration
    LANGFLOW_DATABASE_URL=postgresql://myuser:mypassword@postgres:5432/langflow
    LANGFLOW_CONFIG_DIR=/app/langflow
    LANGFLOW_SUPERUSER_PASSWORD=replace-with-a-strong-password
  2. Modify the docker-compose.yml file to reference the .env file for both the langflow and postgres services:

    services:
    langflow:
    environment:
    - LANGFLOW_DATABASE_URL=${LANGFLOW_DATABASE_URL}
    - LANGFLOW_CONFIG_DIR=${LANGFLOW_CONFIG_DIR}
    postgres:
    environment:
    - POSTGRES_USER=${POSTGRES_USER}
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    - POSTGRES_DB=${POSTGRES_DB}

For a complete list of available environment variables, see Langflow environment variables.

For more customization options, see Customize the Langflow Docker image with your own code.

Package your flow as a Docker image​

This section shows you how to create a Dockerfile that builds a Docker image containing your Langflow flow. This approach is useful when you want to distribute a specific flow as a standalone container or deploy it to environments like Kubernetes.

Unlike the previous sections that use pre-built images, this method builds a custom image with your flow embedded inside it.

  1. Create a project directory, and change directory into it.

    mkdir langflow-custom && cd langflow-custom
  2. Add your flow's JSON file to the directory. You can download an example, or use your own:

    # Download an example flow
    wget https://raw.githubusercontent.com/langflow-ai/langflow-helm-charts/refs/heads/main/examples/flows/basic-prompting-hello-world.json

    # Or copy your own flow file
    cp /path/to/your/flow.json .
  3. Create a Dockerfile to build your custom image:

    FROM langflowai/langflow:latest
    RUN mkdir /app/flows
    COPY ./*.json /app/flows/
    ENV LANGFLOW_LOAD_FLOWS_PATH=/app/flows

This Dockerfile uses the official Langflow image as the base, creates a directory for your flows, copies your JSON flow files into the directory, and sets the environment variable to tell Langflow where to find the flows.

  1. Build and test your custom image:

    docker build -t myuser/langflow-custom:1.0.0 .
    docker run -p 7860:7860 -e LANGFLOW_AUTO_LOGIN=true myuser/langflow-custom:1.0.0
  2. Push your image to Docker Hub (optional):

    docker push myuser/langflow-custom:1.0.0

Your custom image now contains your flow and can be deployed anywhere Docker runs. For Kubernetes deployment, see Deploy the Langflow production environment on Kubernetes.

Customize the Langflow Docker image with your own code​

While the previous section showed how to package a flow with a Docker image, this section shows how to customize the Langflow application itself. This is useful when you need to add custom Python packages or dependencies, modify Langflow's configuration or settings, include custom components or tools, or add your own code to extend Langflow's functionality.

This example demonstrates how to customize the Message History component, but the same approach can be used for any code modifications.

FROM langflowai/langflow:latest

# Set working directory
WORKDIR /app

# Copy your modified memory component
COPY src/lfx/src/lfx/components/helpers/memory.py /tmp/memory.py

# Find the site-packages directory where langflow is installed
RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt

# Replace the file in the site-packages location
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
echo "Site packages at: $SITE_PACKAGES" && \
mkdir -p "$SITE_PACKAGES/langflow/components/helpers" && \
cp /tmp/memory.py "$SITE_PACKAGES/langflow/components/helpers/"

# Clear Python cache in the site-packages directory only
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
find "$SITE_PACKAGES" -name "*.pyc" -delete && \
find "$SITE_PACKAGES" -name "__pycache__" -type d -exec rm -rf {} +

# Expose the default Langflow port
EXPOSE 7860

# Command to run Langflow
CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]

To use this custom Dockerfile, do the following:

  1. Create a directory for your custom Langflow setup:

    mkdir langflow-custom && cd langflow-custom
  2. Create the necessary directory structure for your custom code. In this example, Langflow expects memory.py to exist in the /helpers directory, so you create a directory in that location.

    mkdir -p src/lfx/src/lfx/components/helpers
  3. Place your modified memory.py file in the /helpers directory.

  4. Create a new file named Dockerfile in your langflow-custom directory, and then copy the Dockerfile contents shown above into it.

  5. Build and run the image:

    docker build -t myuser/langflow-custom:1.0.0 .
    docker run -p 7860:7860 -e LANGFLOW_AUTO_LOGIN=true myuser/langflow-custom:1.0.0

This approach can be adapted for any other components or custom code you want to add to Langflow by modifying the file paths and component names.

Upgrade the Langflow Docker image​

Check where your container stores data

Unless you set LANGFLOW_DATABASE_URL or LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true, Langflow stores its SQLite database inside the container, not on a mounted volume. Unless you set LANGFLOW_CONFIG_DIR to the mounted path, Langflow also stores its secret key and uploaded files inside the container. Removing or recreating that container deletes this data, even if a volume is mounted.

If your current container was started without these settings, move its data to a volume before you upgrade.

To upgrade a Langflow Docker deployment without losing your database or flows, do the following:

  1. Keep data on persistent volumes, so when you upgrade Langflow, you will replace only the container image. Mount a Docker volume or bind mount at the path in LANGFLOW_CONFIG_DIR, and keep the database outside of the container. To use PostgreSQL, set LANGFLOW_DATABASE_URL. To keep SQLite, set LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true, which stores the database in the config directory. For example, this Docker Compose file uses a bind mount for Langflow data (./langflow-data on the host) and a named volume for the PostgreSQL database (langflow-postgres):

    services:
    langflow:
    image: langflowai/langflow:1.8.0
    ports:
    - "7860:7860"
    depends_on:
    - postgres
    environment:
    - LANGFLOW_DATABASE_URL=postgresql://langflow:langflow@postgres:5432/langflow
    - LANGFLOW_CONFIG_DIR=/app/langflow
    - LANGFLOW_SUPERUSER_PASSWORD=${LANGFLOW_SUPERUSER_PASSWORD}
    volumes:
    - ./langflow-data:/app/langflow
    postgres:
    # Pinned to a specific Debian base (trixie) so the postgres:16 tag does
    # not silently roll its OS, which triggers a glibc collation mismatch
    # warning on existing volumes. See https://github.com/langflow-ai/langflow/issues/9608
    image: postgres:16-trixie
    environment:
    POSTGRES_USER: langflow
    POSTGRES_PASSWORD: langflow
    POSTGRES_DB: langflow
    volumes:
    - langflow-postgres:/var/lib/postgresql/data

    volumes:
    langflow-postgres:

    On Linux, if ./langflow-data doesn't exist, Docker creates it owned by root, and Langflow fails to start with a PermissionError. Before you start Langflow, create the directory next to the Compose file, and make the Langflow user (UID 1000) its owner:

    mkdir -p langflow-data
    sudo chown -R 1000:0 langflow-data

    For additional examples, see the Docker Compose configuration and the docker_example compose file.

  2. Pull the new image and update the image tag in your docker-compose.yml or docker run command.

    With Docker Compose, set the image in your compose file, such as image: langflowai/langflow:1.8.0, and then pull:

    docker compose pull

    With docker run, pull the image:

    docker pull langflowai/langflow:1.8.0
  3. Restart the container. The same volumes will be reattached, so your database and flows are preserved.

    With Docker Compose:

    docker compose up -d

    With docker run, stop and remove the old container, and then start a new container with the same volume mount and the new image tag:

    docker run -p 7860:7860 \
    -v langflow-data:/app/langflow \
    -e LANGFLOW_CONFIG_DIR=/app/langflow \
    -e LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true \
    -e LANGFLOW_SUPERUSER_PASSWORD=replace-with-a-strong-password \
    langflowai/langflow:1.8.0

    This command stores the SQLite database, secret key, and uploaded files in the langflow-data volume. To use PostgreSQL instead, replace LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true with LANGFLOW_DATABASE_URL.

    Images 1.8.0 through 1.9.3 don't include the /app/langflow directory. When Docker mounts a new named volume there, root owns the volume, and Langflow fails to start with a PermissionError. Before you start one of these images, make the Langflow user (UID 1000) the owner of the volume:

    docker run --rm --user root \
    -v langflow-data:/app/langflow \
    langflowai/langflow:1.8.0 \
    chown -R 1000:0 /app/langflow

    The steps to move data from a container to a volume include this change of owner.

This approach keeps the persistent volumes separate from the Langflow container, so you can upgrade the Langflow application without losing data.

Move data from a container to a volume​

If your current container was started without LANGFLOW_DATABASE_URL or LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true, its SQLite database is inside the container. If it was also started without LANGFLOW_CONFIG_DIR, its secret key and uploaded files are inside the container too. Without the original secret key, Langflow can't decrypt saved credentials, such as Credential global variables.

To keep this data, copy it to a volume before you remove the container:

  1. While the container is running, list the data files that are stored inside it:

    docker exec OLD_CONTAINER sh -c 'find / -xdev \( -name "langflow*.db" -o -name secret_key \) 2>/dev/null'

    Replace OLD_CONTAINER with the name or ID of the container. To find it, run docker ps. The output lists the paths to copy. The paths depend on the image version. For example:

    /app/data/.cache/langflow/secret_key
    /app/.venv/lib/python3.14/site-packages/langflow/langflow.db

    If the output is empty, the container already stores its data on a volume or in an external database.

  2. Stop the container, so SQLite writes all pending changes to the database file:

    docker stop -t 60 OLD_CONTAINER

    The -t 60 option gives Langflow up to 60 seconds to shut down before Docker kills it.

  3. Copy the config directory, which is the directory that contains secret_key, and the database file to a backup directory on the host. Use the paths from step 1:

    mkdir langflow-backup
    docker cp OLD_CONTAINER:/app/data/.cache/langflow/. langflow-backup/
    docker cp OLD_CONTAINER:/app/.venv/lib/python3.14/site-packages/langflow/langflow.db langflow-backup/

    If step 1 listed only the database file, skip the first docker cp command. The backup contains your secret key, so keep it private.

    Then copy the langflow.db-wal and langflow.db-shm files from the same directory as the database file. These files exist only if Langflow didn't shut down cleanly, and they can hold changes that aren't in langflow.db yet:

    docker cp OLD_CONTAINER:/app/.venv/lib/python3.14/site-packages/langflow/langflow.db-wal langflow-backup/
    docker cp OLD_CONTAINER:/app/.venv/lib/python3.14/site-packages/langflow/langflow.db-shm langflow-backup/

    If Docker reports Could not find the file, the database file already holds all changes.

  4. Copy the backup into the volume, and make the Langflow user (UID 1000) the owner of the files:

    docker run --rm --user root \
    -v langflow-data:/app/langflow \
    -v "$PWD/langflow-backup:/backup:ro" \
    langflowai/langflow:1.8.0 \
    sh -c 'cp -R /backup/. /app/langflow/ && chown -R 1000:0 /app/langflow'

    Replace langflow-data with your volume name, or with the host path of your bind mount, such as "$PWD/langflow-data". Docker Compose adds the project name to volume names. To find the name, run docker volume ls. With Docker Desktop, create the backup directory in a location that Docker can share, such as your home directory.

  5. Start the new container with LANGFLOW_CONFIG_DIR=/app/langflow and LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true, as shown in the docker run command in the upgrade steps. With Docker Compose, add LANGFLOW_SAVE_DB_IN_CONFIG_DIR=true to the environment list. Don't point LANGFLOW_DATABASE_URL at a new PostgreSQL database for this data. That database starts empty, because Langflow doesn't copy SQLite data into it.

  6. Open Langflow, sign in if Langflow asks you to, and confirm that your flows, API keys, and files are present. Then remove the old container:

    docker rm OLD_CONTAINER

If you need to upgrade to a custom image based on a Langflow release, such as to add uv in 1.8.0, first build a derived image from the official image, and then follow the same steps above. Set the custom image in your compose file or docker run, and then pull and restart.

For a minimal Dockerfile that adds uv to the 1.8.0 image, see the release notes (“Docker image no longer includes uv or uvx”).

Was this page helpful?

Support
Search