0

I am using these packages

langchain-core
langchain-community
langchain
pypdf
gradio
langchain_huggingface
langchain-chroma
langchain_groq
python-dotenv 

to develop one python app i build dockers image from these dependencies and its size was 10GB which is huge i have just one code file no other file except why these packages are increasing size upto 10 GB help me if i am missing something these are my code imports for which i have installed these packages

import gradio as gr
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_chroma import Chroma
import logging
from langchain.chains import ConversationChain, RetrievalQA
from langchain_core.output_parsers import StrOutputParser
from langchain_community.document_loaders import (
    PyPDFLoader,
)
from langchain_core.prompts.prompt import PromptTemplate
from langchain.memory import ConversationBufferMemory
from langchain_groq import ChatGroq
from langchain_huggingface import HuggingFaceEmbeddings
import os
from dotenv import load_dotenv

I want to reduce the size of Docker image

2

1 Answer 1

0

Take small base image of python like python-slim or alpine. And also you can use multi-stage build technique to reduce docker image size. I have used both of them I create docker image with all the libraries you have mentioned. For me my docker image size is 6GB.

Below I am sharing code of my Dockerfile you can try that:

Stage 1: Build

FROM python:3.9-slim as builder

Set work directory

WORKDIR /app

Copy the requirements file

COPY requirements.txt .

Install dependencies

RUN pip install --no-cache-dir -r requirements.txt

Stage 2: Final

FROM python:3.9-slim

Set work directory

WORKDIR /app

Copy only the necessary files from the build stage

COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages COPY --from=builder /usr/local/bin /usr/local/bin

Copy the application files

COPY . .

Run the application

CMD ["python", "nlp.py"]

In above file you can see python:3.9-slim is used as base image and muti-stage docker build technique is used to reduce size of docker image. Here mlp.py is single python file to run inside docker container.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.