From f55f67055fc207714d456e0834a42984f1e1b09a Mon Sep 17 00:00:00 2001 From: langchain-infra <144731603+langchain-infra@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:33:01 -0500 Subject: [PATCH] Add dockerfile template (#13240) --- .../langchain_cli/project_template/Dockerfile | 21 +++++++++++++ .../langchain_cli/project_template/README.md | 30 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 libs/cli/langchain_cli/project_template/Dockerfile 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= # 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 +```