Skip to content

Commit d4f35bb

Browse files
committed
docs-add-build-from-source-and-refresh
1 parent 7504eb4 commit d4f35bb

1 file changed

Lines changed: 133 additions & 78 deletions

File tree

docs/docs/Deployment/deployment-docker.mdx

Lines changed: 133 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ import PartialPodmanAlt from '@site/docs/_partial-podman-alt.mdx';
99

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

12-
You can use the Langflow Docker image to start a Langflow container.
13-
14-
This guide demonstrates several ways to deploy Langflow with [Docker](https://docs.docker.com/) and [Docker Compose](https://docs.docker.com/compose/):
12+
This guide demonstrates several ways to run Langflow with [Docker](https://docs.docker.com/) and [Docker Compose](https://docs.docker.com/compose/):
1513

1614
* [Quickstart](#quickstart): Start a Langflow container with default values.
17-
* [Use Docker Compose](#clone): Clone the Langflow repo, and then use Docker Compose to build the Langflow Docker container.
18-
This option provides more control over the configuration, including a persistent PostgreSQL database service, while still using the base Langflow Docker image.
19-
* [Create a custom flow image](#package-your-flow-as-a-docker-image): Use a Dockerfile to package a flow as a Docker image.
20-
* [Create a custom Langflow image](#customize-the-langflow-docker-image): Use a Dockerfile to package a custom Langflow Docker image that includes your own code, custom dependencies, or other modifications.
21-
* [Upgrade the Langflow Docker image](#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.
15+
* [Use Docker Compose](#docker-compose): Run Langflow with a persistent PostgreSQL database and configurable environment variables.
16+
* [Customize the Docker image](#customize): Package a flow or add your own code into a custom image built on top of the official Langflow image.
17+
* [Build and run the Docker image from source](#build-from-source): Build a Docker image from a local clone of the repo, or start a full development environment with hot reload on both frontend and backend.
18+
* [Upgrade the Langflow Docker image](#upgrade-the-langflow-docker-image): Upgrade to a newer image without losing your database or flows.
2219

23-
## Quickstart: Start a Langflow container with default values {#quickstart}
20+
## Quickstart {#quickstart}
2421

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

@@ -31,19 +28,13 @@ docker run -p 7860:7860 langflowai/langflow:latest
3128
Then, access Langflow at `http://localhost:7860/`.
3229

3330
This container runs a pre-built Docker image with default settings.
34-
For more control over the configuration, see [Clone the repo and run the Langflow Docker container](#clone).
35-
36-
## Clone the repo and run the Langflow Docker container {#clone}
31+
For more control over the configuration, see [Use Docker Compose](#docker-compose).
3732

38-
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.
33+
## Use Docker Compose {#docker-compose}
3934

40-
The default deployment with Docker Compose includes the following:
35+
Docker Compose gives you more control over your configuration, such as setting environment variables, using a persistent PostgreSQL database instead of the default SQLite database, and including custom dependencies.
4136

42-
- **Langflow service**: Runs the latest Langflow image with PostgreSQL as the database.
43-
- **PostgreSQL service**: Provides persistent data storage for flows, users, and settings.
44-
- **Persistent volumes**: Ensures your data survives container restarts.
45-
46-
The complete Docker Compose configuration is available in `docker_example/docker-compose.yml`.
37+
The Langflow repo includes a ready-to-use Compose file at `docker_example/docker-compose.yml` that pulls the latest Langflow image from Docker Hub and includes persistent volume storage with PostgreSQL.
4738

4839
1. Clone the Langflow repository:
4940

@@ -65,11 +56,13 @@ The complete Docker Compose configuration is available in `docker_example/docker
6556

6657
4. Access Langflow at `http://localhost:7860/`.
6758

68-
### Customize your deployment
59+
## Customize the Docker Compose file {#customize}
60+
61+
Customize the Docker Compose file to fit your deployment's requirements.
6962

70-
You can customize the Docker Compose configuration to fit your specific deployment.
63+
### Include environment variables
7164

72-
For example, to configure the container's database credentials using a `.env` file, do the following:
65+
Configure a container's database credentials using a `.env` file.
7366

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

@@ -101,15 +94,12 @@ For example, to configure the container's database credentials using a `.env` fi
10194
10295
For a complete list of available environment variables, see [Langflow environment variables](/environment-variables).
10396
104-
For more customization options, see [Customize the Langflow Docker image with your own code](#customize-the-langflow-docker-image).
97+
### Package a flow into the image
10598
106-
## Package your flow as a Docker image {#package-your-flow-as-a-docker-image}
99+
Embed a flow JSON directly into a Docker image.
100+
This is useful for distributing a specific flow as a standalone container or deploying it to environments like Kubernetes.
107101
108-
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.
109-
110-
Unlike the previous sections that use pre-built images, this method builds a custom image with your flow embedded inside it.
111-
112-
1. Create a project directory, and change directory into it.
102+
1. Create a project directory and change into it:
113103
114104
```bash
115105
mkdir langflow-custom && cd langflow-custom
@@ -125,7 +115,7 @@ Unlike the previous sections that use pre-built images, this method builds a cus
125115
cp /path/to/your/flow.json .
126116
```
127117

128-
3. Create a Dockerfile to build your custom image:
118+
3. Create a `Dockerfile`:
129119

130120
```dockerfile
131121
FROM langflowai/langflow:latest
@@ -134,86 +124,151 @@ Unlike the previous sections that use pre-built images, this method builds a cus
134124
ENV LANGFLOW_LOAD_FLOWS_PATH=/app/flows
135125
```
136126

137-
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.
138-
139-
4. Build and test your custom image:
127+
4. Build, test, and optionally push your image:
140128

141129
```bash
142130
docker build -t myuser/langflow-custom:1.0.0 .
143131
docker run -p 7860:7860 myuser/langflow-custom:1.0.0
132+
docker push myuser/langflow-custom:1.0.0 # optional
133+
```
134+
135+
For Kubernetes deployment, see [Deploy the Langflow production environment on Kubernetes](/deployment-kubernetes-prod).
136+
137+
### Add custom code or dependencies
138+
139+
Patch custom code into the pre-built image's installation.
140+
This is useful when you need to add custom Python packages, replace a built-in component, or make targeted changes without a [full source build](#build-from-source).
141+
142+
This example replaces the built-in **Message History** component, but the same pattern applies to any component or file.
143+
144+
1. Create a directory for your custom Langflow setup:
145+
146+
```bash
147+
mkdir langflow-custom && cd langflow-custom
144148
```
145149

146-
5. Push your image to Docker Hub (optional):
150+
2. Create the directory structure that mirrors the component path:
147151

148152
```bash
149-
docker push myuser/langflow-custom:1.0.0
153+
mkdir -p src/lfx/src/lfx/components/helpers
154+
```
155+
156+
3. Place your modified `memory.py` file in that directory.
157+
158+
4. Create a `Dockerfile`:
159+
160+
```dockerfile
161+
FROM langflowai/langflow:latest
162+
163+
WORKDIR /app
164+
165+
COPY src/lfx/src/lfx/components/helpers/memory.py /tmp/memory.py
166+
167+
RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt
168+
169+
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
170+
mkdir -p "$SITE_PACKAGES/langflow/components/helpers" && \
171+
cp /tmp/memory.py "$SITE_PACKAGES/langflow/components/helpers/"
172+
173+
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
174+
find "$SITE_PACKAGES" -name "*.pyc" -delete && \
175+
find "$SITE_PACKAGES" -name "__pycache__" -type d -exec rm -rf {} +
176+
177+
EXPOSE 7860
178+
CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
150179
```
151180

152-
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](/deployment-kubernetes-prod).
181+
5. Build and run the image:
153182

154-
## Customize the Langflow Docker image with your own code {#customize-the-langflow-docker-image}
183+
```bash
184+
docker build -t myuser/langflow-custom:1.0.0 .
185+
docker run -p 7860:7860 myuser/langflow-custom:1.0.0
186+
```
155187

156-
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.
157188

158-
This example demonstrates how to customize the **Message History** component, but the same approach can be used for any code modifications.
189+
## Build and run the Docker image from source {#build-from-source}
159190

160-
```dockerfile
161-
FROM langflowai/langflow:latest
191+
If you've cloned the Langflow repository and want to build and run your local changes inside a Docker container, run:
162192

163-
# Set working directory
164-
WORKDIR /app
193+
```shell
194+
make docker_build
195+
```
165196

166-
# Copy your modified memory component
167-
COPY src/lfx/src/lfx/components/helpers/memory.py /tmp/memory.py
197+
This builds `docker/build_and_push.Dockerfile` and tags the result `langflow:<version>`.
168198

169-
# Find the site-packages directory where langflow is installed
170-
RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt
199+
To run the image after building, run:
171200

172-
# Replace the file in the site-packages location
173-
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
174-
echo "Site packages at: $SITE_PACKAGES" && \
175-
mkdir -p "$SITE_PACKAGES/langflow/components/helpers" && \
176-
cp /tmp/memory.py "$SITE_PACKAGES/langflow/components/helpers/"
201+
```shell
202+
docker run -p 7860:7860 langflow:<version>
203+
```
177204

178-
# Clear Python cache in the site-packages directory only
179-
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
180-
find "$SITE_PACKAGES" -name "*.pyc" -delete && \
181-
find "$SITE_PACKAGES" -name "__pycache__" -type d -exec rm -rf {} +
205+
Replace `<version>` with the version printed during the build.
206+
You can also find the version in `pyproject.toml` at the repo root.
182207

183-
# Expose the default Langflow port
184-
EXPOSE 7860
208+
To build only the LFX executor CLI image instead of the full Langflow application, run:
185209

186-
# Command to run Langflow
187-
CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
210+
```shell
211+
make lfx_docker_build
188212
```
189213

190-
To use this custom Dockerfile, do the following:
214+
This builds `src/lfx/docker/Dockerfile` and tags the result `lfx:latest`.
215+
It produces a lightweight Alpine-based image that contains only the `lfx` CLI tool, with no frontend or Langflow UI.
191216

192-
1. Create a directory for your custom Langflow setup:
217+
### Write a custom source-based Dockerfile
193218

194-
```bash
195-
mkdir langflow-custom && cd langflow-custom
219+
When writing a source-based Dockerfile, you must copy the manifest files (`pyproject.toml`, `README.md`, and `uv.lock` where present) for every workspace member before running `uv sync`.
220+
The workspace members are defined in `[tool.uv.workspace]` in the root `pyproject.toml`.
221+
222+
1. To copy all manifest files to your Dockerfile, include the following:
223+
224+
```dockerfile
225+
COPY ./uv.lock /app/uv.lock
226+
COPY ./README.md /app/README.md
227+
COPY ./pyproject.toml /app/pyproject.toml
228+
COPY ./src/backend/base/README.md /app/src/backend/base/README.md
229+
COPY ./src/backend/base/uv.lock /app/src/backend/base/uv.lock
230+
COPY ./src/backend/base/pyproject.toml /app/src/backend/base/pyproject.toml
231+
COPY ./src/lfx/README.md /app/src/lfx/README.md
232+
COPY ./src/lfx/pyproject.toml /app/src/lfx/pyproject.toml
233+
COPY ./src/sdk/README.md /app/src/sdk/README.md
234+
COPY ./src/sdk/pyproject.toml /app/src/sdk/pyproject.toml
196235
```
197236

198-
2. Create the necessary directory structure for your custom code.
199-
In this example, Langflow expects `memory.py` to exist in the `/helpers` directory, so you create a directory in that location.
237+
2. To install dependencies and copy the source, include the following:
200238

201-
```bash
202-
mkdir -p src/lfx/src/lfx/components/helpers
239+
```dockerfile
240+
RUN --mount=type=cache,target=/root/.cache/uv \
241+
uv sync --frozen --no-install-project --no-editable --extra postgresql --no-group dev
242+
243+
COPY ./src /app/src
203244
```
204245

205-
3. Place your modified `memory.py` file in the `/helpers` directory.
246+
For an example, see [`docker/build_and_push_with_extras.Dockerfile`](https://github.com/langflow-ai/langflow/blob/main/docker/build_and_push_with_extras.Dockerfile).
206247

207-
4. Create a new file named `Dockerfile` in your `langflow-custom` directory, and then copy the Dockerfile contents shown above into it.
248+
### Start a development environment with `make dcdev_up`
208249

209-
5. Build and run the image:
250+
`make dcdev_up` starts a full development environment from source using [`docker/dev.docker-compose.yml`](https://github.com/langflow-ai/langflow/blob/main/docker/dev.docker-compose.yml).
251+
This is useful if you want to work on the Langflow codebase within a container.
210252

211-
```bash
212-
docker build -t myuser/langflow-custom:1.0.0 .
213-
docker run -p 7860:7860 myuser/langflow-custom:1.0.0
214-
```
253+
To build the Langflow dcdev image, run:
254+
255+
```shell
256+
make dcdev_up
257+
```
258+
259+
Access the backend and Langflow UI at `http://localhost:7860/`.
260+
Access the frontend dev server at `http://localhost:3000/`.
261+
262+
The following environment variables are set by default:
263+
264+
| Variable | Default value | Description |
265+
|---|---|---|
266+
| `LANGFLOW_DATABASE_URL` | `postgresql://langflow:langflow@postgres:5432/langflow` | PostgreSQL connection string |
267+
| `LANGFLOW_SUPERUSER` | `langflow` | Initial admin username |
268+
| `LANGFLOW_SUPERUSER_PASSWORD` | `langflow` | Initial admin password |
269+
| `LANGFLOW_CONFIG_DIR` | `/var/lib/langflow` | Directory for Langflow config and data |
215270

216-
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.
271+
To override these values, create a `.env` file in the repo root before running `make dcdev_up`.
217272

218273
## Upgrade the Langflow Docker image {#upgrade-the-langflow-docker-image}
219274

@@ -243,7 +298,7 @@ For example, this Docker Compose file uses a bind mount for Langflow data (`./la
243298
langflow-postgres:
244299
```
245300
246-
For additional examples, see the [Docker Compose configuration](#clone) and the [docker_example compose file](https://github.com/langflow-ai/langflow/blob/main/docker_example/docker-compose.yml).
301+
For additional examples, see the [Docker Compose configuration](#docker-compose) and the [docker_example compose file](https://github.com/langflow-ai/langflow/blob/main/docker_example/docker-compose.yml).
247302
248303
2. Pull the new image and update the image tag in your `docker-compose.yml` or `docker run` command.
249304

@@ -278,4 +333,4 @@ This approach keeps the persistent volumes separate from the Langflow container,
278333
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.
279334
Set the custom image in your compose file or `docker run`, and then pull and restart.
280335

281-
For a minimal Dockerfile that adds `uv` to the 1.8.0 image, see the [release notes](/release-notes) (Docker image no longer includes uv or uvx).
336+
For a minimal Dockerfile that adds `uv` to the 1.8.0 image, see the [release notes](/release-notes) ("Docker image no longer includes uv or uvx").

0 commit comments

Comments
 (0)