Skip to content

The agent engineering platform.

Add dockerfile template (#13240)

langchain-infraf55f67055fc2
diff --git a/libs/cli/langchain_cli/project_template/Dockerfile b/libs/cli/langchain_cli/project_template/Dockerfile
new file mode 100644
index 0000000000..510706eb19
--- /dev/null
+++ b/libs/cli/langchain_cli/project_template/Dockerfile
@@ -0,0 +1,21 @@
+FROM python:3.11-slim
+
+RUN pip install poetry==1.6.1
+
+RUN poetry config virtualenvs.create false
+
+WORKDIR /code
+
+COPY ./pyproject.toml ./poetry.lock* ./
+
+COPY ./packages ./packages
+
+RUN poetry install --no-interaction --no-ansi --no-root
+
+COPY ./app ./app
+
+RUN poetry install --no-interaction --no-ansi
+
+EXPOSE 8080
+
+CMD exec uvicorn app.server:app --host 0.0.0.0 --port 8080
diff --git a/libs/cli/langchain_cli/project_template/README.md b/libs/cli/langchain_cli/project_template/README.md
index 241a5cebc4..cc5726bb2c 100644
--- a/libs/cli/langchain_cli/project_template/README.md
+++ b/libs/cli/langchain_cli/project_template/README.md
@@ -47,3 +47,33 @@ export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "defaul
```bash
langchain serve
```
+
+## Running in Docker
+
+This project folder includes a Dockerfile that allows you to easily build and host your LangServe app.
+
+### Building the Image
+
+To build the image, you simply:
+
+```shell
+docker build . -t my-langserve-app
+```
+
+If you tag your image with something other than `my-langserve-app`,
+note it for use in the next step.
+
+### Running the Image Locally
+
+To run the image, you'll need to include any environment variables
+necessary for your application.
+
+In the below example, we inject the `OPENAI_API_KEY` environment
+variable with the value set in my local environment
+(`$OPENAI_API_KEY`)
+
+We also expose port 8080 with the `-p 8080:8080` option.
+
+```shell
+docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -p 8080:8080 my-langserve-app
+```