Skip to content

Commit bb930e2

Browse files
authored
docs: build docker from source (#13041)
* docs-add-build-from-source-and-refresh * peer review * peer-review * peer-review * peer-review
1 parent ca29afa commit bb930e2

1 file changed

Lines changed: 158 additions & 82 deletions

File tree

docs/docs/Deployment/deployment-docker.mdx

Lines changed: 158 additions & 82 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}
37-
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.
31+
For more control over the configuration, see [Use Docker Compose](#docker-compose).
3932

40-
The default deployment with Docker Compose includes the following:
33+
## Use Docker Compose {#docker-compose}
4134

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.
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.
4536

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}
6960

70-
You can customize the Docker Compose configuration to fit your specific deployment.
61+
Customize the Docker Compose file to fit your deployment's requirements.
7162

72-
For example, to configure the container's database credentials using a `.env` file, do the following:
63+
### Include environment variables
64+
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

@@ -84,7 +77,7 @@ For example, to configure the container's database credentials using a `.env` fi
8477
LANGFLOW_CONFIG_DIR=/app/langflow
8578
```
8679

87-
2. Modify the `docker-compose.yml` file to reference the `.env` file for both the `langflow` and `postgres` services:
80+
2. Edit `docker-compose.yml` to replace the hardcoded values with variable references for both the `langflow` and `postgres` services:
8881

8982
```yaml
9083
services:
@@ -99,17 +92,16 @@ For example, to configure the container's database credentials using a `.env` fi
9992
- POSTGRES_DB=${POSTGRES_DB}
10093
```
10194
102-
For a complete list of available environment variables, see [Langflow environment variables](/environment-variables).
95+
With variable references in place, Docker Compose reads the values from your `.env` file at startup.
10396

104-
For more customization options, see [Customize the Langflow Docker image with your own code](#customize-the-langflow-docker-image).
105-
106-
## Package your flow as a Docker image {#package-your-flow-as-a-docker-image}
97+
For a complete list of available environment variables, see [Langflow environment variables](/environment-variables).
10798

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.
99+
### Package a flow into the image
109100

110-
Unlike the previous sections that use pre-built images, this method builds a custom image with your flow embedded inside it.
101+
Embed a flow JSON directly into a Docker image.
102+
This is useful for distributing a specific flow as a standalone container or deploying it to environments like Kubernetes.
111103

112-
1. Create a project directory, and change directory into it.
104+
1. Create a project directory and change into it:
113105

114106
```bash
115107
mkdir langflow-custom && cd langflow-custom
@@ -125,7 +117,7 @@ Unlike the previous sections that use pre-built images, this method builds a cus
125117
cp /path/to/your/flow.json .
126118
```
127119

128-
3. Create a Dockerfile to build your custom image:
120+
3. Create a `Dockerfile`:
129121

130122
```dockerfile
131123
FROM langflowai/langflow:latest
@@ -134,86 +126,170 @@ Unlike the previous sections that use pre-built images, this method builds a cus
134126
ENV LANGFLOW_LOAD_FLOWS_PATH=/app/flows
135127
```
136128

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:
129+
4. Build, test, and optionally push your image:
140130

141131
```bash
142132
docker build -t myuser/langflow-custom:1.0.0 .
143133
docker run -p 7860:7860 myuser/langflow-custom:1.0.0
134+
docker push myuser/langflow-custom:1.0.0 # optional
144135
```
145136

146-
5. Push your image to Docker Hub (optional):
137+
For Kubernetes deployment, see [Deploy the Langflow production environment on Kubernetes](/deployment-kubernetes-prod).
138+
139+
### Add custom code or dependencies
140+
141+
Patch custom code into the pre-built image's installation.
142+
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).
143+
144+
This example replaces the built-in **Message History** component, but the same pattern applies to any component or file.
145+
146+
1. Create a directory for your custom Langflow setup:
147147

148148
```bash
149-
docker push myuser/langflow-custom:1.0.0
149+
mkdir langflow-custom && cd langflow-custom
150150
```
151151

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).
152+
2. Create the directory structure that mirrors the component path:
153153

154-
## Customize the Langflow Docker image with your own code {#customize-the-langflow-docker-image}
154+
```bash
155+
mkdir -p src/lfx/src/lfx/components/models_and_agents
156+
```
155157

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.
158+
3. Place your modified `memory.py` file in that directory.
157159

158-
This example demonstrates how to customize the **Message History** component, but the same approach can be used for any code modifications.
160+
4. Create a `Dockerfile`:
159161

160-
```dockerfile
161-
FROM langflowai/langflow:latest
162+
```dockerfile
163+
FROM langflowai/langflow:latest
164+
165+
WORKDIR /app
166+
167+
COPY src/lfx/src/lfx/components/models_and_agents/memory.py /tmp/memory.py
168+
169+
RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt
162170
163-
# Set working directory
164-
WORKDIR /app
171+
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
172+
mkdir -p "$SITE_PACKAGES/lfx/components/models_and_agents" && \
173+
cp /tmp/memory.py "$SITE_PACKAGES/lfx/components/models_and_agents/"
165174
166-
# Copy your modified memory component
167-
COPY src/lfx/src/lfx/components/helpers/memory.py /tmp/memory.py
175+
RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \
176+
find "$SITE_PACKAGES" -name "*.pyc" -delete && \
177+
find "$SITE_PACKAGES" -name "__pycache__" -type d -exec rm -rf {} +
178+
179+
EXPOSE 7860
180+
CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
181+
```
182+
183+
5. Build and run the image:
168184

169-
# Find the site-packages directory where langflow is installed
170-
RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt
185+
```bash
186+
docker build -t myuser/langflow-custom:1.0.0 .
187+
docker run -p 7860:7860 myuser/langflow-custom:1.0.0
188+
```
171189

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/"
177190

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 {} +
191+
## Build and run the Docker image from source {#build-from-source}
182192

183-
# Expose the default Langflow port
184-
EXPOSE 7860
193+
:::tip
194+
Both `make docker_build` and `make lfx_docker_build` use Podman by default. If you have Docker installed instead, pass the alias `DOCKER=docker` on the command line:
185195

186-
# Command to run Langflow
187-
CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
196+
```shell
197+
make docker_build DOCKER=docker
188198
```
199+
:::
189200

190-
To use this custom Dockerfile, do the following:
191201

192-
1. Create a directory for your custom Langflow setup:
202+
If you've cloned the Langflow repository and want to build and run your local changes inside a Docker container, run:
193203

194-
```bash
195-
mkdir langflow-custom && cd langflow-custom
204+
```shell
205+
make docker_build
196206
```
197207

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.
208+
This builds `docker/build_and_push.Dockerfile` and tags the result `langflow:<version>`.
200209

201-
```bash
202-
mkdir -p src/lfx/src/lfx/components/helpers
210+
To run the image after building, run:
211+
212+
```shell
213+
docker run -p 7860:7860 langflow:<version>
214+
```
215+
216+
Replace `<version>` with the version in `pyproject.toml` at the repo root.
217+
218+
To build only the LFX executor CLI image instead of the full Langflow application, run:
219+
220+
```shell
221+
make lfx_docker_build
222+
```
223+
224+
This builds `src/lfx/docker/Dockerfile` and tags the result `lfx:latest`.
225+
It produces a lightweight Alpine-based image that contains only the `lfx` CLI tool, with no frontend or Langflow UI.
226+
227+
The build context is the repo root, not `src/lfx/`. The Dockerfile copies from `pyproject.toml`, `uv.lock`, `src/lfx/`, and `src/sdk/`, so the full workspace is sent to the daemon. A root `.dockerignore` file partially mitigates this, but the first build will be slower than you might expect for a small CLI image.
228+
229+
### Write a custom source-based Dockerfile
230+
231+
When writing a source-based Dockerfile, you must copy the manifest files (`pyproject.toml`, `README.md`, and `uv.lock` where present) for the workspace members that `uv sync` needs to resolve dependencies before source is available.
232+
The workspace members are defined in `[tool.uv.workspace]` in the root `pyproject.toml`.
233+
You do not need to copy manifests for members like `src/langflow-stepflow` that are not required for the initial dependency-only sync.
234+
The full source is copied later with `COPY ./src`, which brings those omitted members into the image before the second `uv sync`.
235+
236+
1. To copy all manifest files to your Dockerfile, include the following:
237+
238+
```dockerfile
239+
COPY ./uv.lock /app/uv.lock
240+
COPY ./README.md /app/README.md
241+
COPY ./pyproject.toml /app/pyproject.toml
242+
COPY ./src/backend/base/README.md /app/src/backend/base/README.md
243+
COPY ./src/backend/base/pyproject.toml /app/src/backend/base/pyproject.toml
244+
COPY ./src/lfx/README.md /app/src/lfx/README.md
245+
COPY ./src/lfx/pyproject.toml /app/src/lfx/pyproject.toml
246+
COPY ./src/sdk/README.md /app/src/sdk/README.md
247+
COPY ./src/sdk/pyproject.toml /app/src/sdk/pyproject.toml
248+
COPY ./src/bundles /app/src/bundles
203249
```
204250

205-
3. Place your modified `memory.py` file in the `/helpers` directory.
251+
2. To install dependencies and copy the source, include the following:
206252

207-
4. Create a new file named `Dockerfile` in your `langflow-custom` directory, and then copy the Dockerfile contents shown above into it.
253+
```dockerfile
254+
RUN --mount=type=cache,target=/root/.cache/uv \
255+
uv sync --frozen --no-install-project --no-editable --extra postgresql --no-group dev
208256
209-
5. Build and run the image:
257+
COPY ./src /app/src
210258
211-
```bash
212-
docker build -t myuser/langflow-custom:1.0.0 .
213-
docker run -p 7860:7860 myuser/langflow-custom:1.0.0
259+
RUN --mount=type=cache,target=/root/.cache/uv \
260+
uv sync --frozen --no-editable --extra postgresql --no-group dev
214261
```
215262

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.
263+
The first `uv sync` installs only dependencies before the source is copied, so that Docker can cache that layer. The second `uv sync` installs the project packages (`langflow`, `lfx`) from the copied source. Both calls are required. Omitting the second will produce a container with all dependencies present but the project packages missing, which fails at runtime.
264+
265+
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).
266+
267+
### Start a development environment with `make dcdev_up`
268+
269+
`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).
270+
This is useful if you want to work on the Langflow codebase within a container.
271+
272+
To build the Langflow dcdev image, run:
273+
274+
```shell
275+
make dcdev_up
276+
```
277+
278+
Access the backend and Langflow UI at `http://localhost:7860/`.
279+
Access the frontend dev server at `http://localhost:3000/`.
280+
281+
The following environment variables are set by default:
282+
283+
| Variable | Default value | Description |
284+
|---|---|---|
285+
| `LANGFLOW_DATABASE_URL` | `postgresql://langflow:langflow@postgres:5432/langflow` | PostgreSQL connection string |
286+
| `LANGFLOW_SUPERUSER` | `langflow` | Initial admin username |
287+
| `LANGFLOW_SUPERUSER_PASSWORD` | `langflow` | Initial admin password |
288+
| `LANGFLOW_CONFIG_DIR` | `/var/lib/langflow` | Directory for Langflow config and data |
289+
290+
To override these values, edit `docker/dev.docker-compose.yml` directly.
291+
292+
`docker/dev.docker-compose.yml` uses literal values in its `environment:` block, such as `- LANGFLOW_SUPERUSER=langflow`. Docker Compose v2 gives `environment:` block literal values higher precedence than shell-exported variables and `env_file:`, so neither `export LANGFLOW_SUPERUSER=myadmin` or a `.env` file will override them. Edit the file directly instead.
217293

218294
## Upgrade the Langflow Docker image {#upgrade-the-langflow-docker-image}
219295

@@ -226,7 +302,7 @@ For example, this Docker Compose file uses a bind mount for Langflow data (`./la
226302
```yaml
227303
services:
228304
langflow:
229-
image: langflowai/langflow:1.8.0
305+
image: langflowai/langflow:1.11.0
230306
environment:
231307
- LANGFLOW_CONFIG_DIR=/app/langflow
232308
volumes:
@@ -243,11 +319,11 @@ For example, this Docker Compose file uses a bind mount for Langflow data (`./la
243319
langflow-postgres:
244320
```
245321

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).
322+
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).
247323

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

250-
With Docker Compose, set the image in your compose file, such as `image: langflowai/langflow:1.8.0`, and then pull:
326+
With Docker Compose, set the image in your compose file, such as `image: langflowai/langflow:1.11.0`, and then pull:
251327

252328
```bash
253329
docker compose pull
@@ -256,7 +332,7 @@ For example, this Docker Compose file uses a bind mount for Langflow data (`./la
256332
With `docker run`, pull the image:
257333

258334
```bash
259-
docker pull langflowai/langflow:1.8.0
335+
docker pull langflowai/langflow:1.11.0
260336
```
261337

262338
3. Restart the container. The same volumes will be reattached, so your database and flows are preserved.
@@ -270,12 +346,12 @@ For example, this Docker Compose file uses a bind mount for Langflow data (`./la
270346
With `docker run`, use the same volume mount and the new image tag:
271347

272348
```bash
273-
docker run -p 7860:7860 -v langflow-data:/app/langflow langflowai/langflow:1.8.0
349+
docker run -p 7860:7860 -v langflow-data:/app/langflow langflowai/langflow:1.11.0
274350
```
275351

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

278354
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.
279355
Set the custom image in your compose file or `docker run`, and then pull and restart.
280356

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).
357+
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)